summaryrefslogtreecommitdiff
path: root/lib/libpcap/pcap.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libpcap/pcap.c')
-rw-r--r--lib/libpcap/pcap.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/libpcap/pcap.c b/lib/libpcap/pcap.c
index 889e4aabb21..ee14262af6d 100644
--- a/lib/libpcap/pcap.c
+++ b/lib/libpcap/pcap.c
@@ -1,8 +1,7 @@
-/* $OpenBSD */
-/* $NetBSD: pcap.c,v 1.2 1995/03/06 11:39:05 mycroft Exp $ */
+/* $OpenBSD: pcap.c,v 1.4 1996/07/12 13:19:12 mickey Exp $ */
/*
- * Copyright (c) 1993, 1994
+ * Copyright (c) 1993, 1994, 1995, 1996
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,23 +35,34 @@
#ifndef lint
static char rcsid[] =
- "@(#) Header: pcap.c,v 1.12 94/06/12 14:32:23 leres Exp (LBL)";
+ "@(#) Header: pcap.c,v 1.25 96/06/05 21:45:26 leres Exp (LBL)";
#endif
#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#ifdef HAVE_OS_PROTO_H
+#include "os-proto.h"
+#endif
+
#include "pcap-int.h"
int
pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
+ register int cc;
+
if (p->sf.rfile != NULL)
return (pcap_offline_read(p, cnt, callback, user));
- else
- return (pcap_read(p, cnt, callback, user));
+ /* XXX keep reading until we get something (or an error occurs) */
+ do {
+ cc = pcap_read(p, cnt, callback, user);
+ } while (cc == 0);
+ return (cc);
}
int
@@ -60,7 +70,7 @@ pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
{
for (;;) {
int n = pcap_dispatch(p, cnt, callback, user);
- if (n < 0)
+ if (n <= 0)
return (n);
if (cnt > 0) {
cnt -= n;
@@ -90,7 +100,7 @@ pcap_next(pcap_t *p, struct pcap_pkthdr *h)
struct singleton s;
s.hdr = h;
- if (pcap_dispatch(p, 1, pcap_oneshot, (u_char*)&s) < 0)
+ if (pcap_dispatch(p, 1, pcap_oneshot, (u_char*)&s) <= 0)
return (0);
return (s.pkt);
}
@@ -155,8 +165,18 @@ pcap_geterr(pcap_t *p)
char *
pcap_strerror(int errnum)
{
-
+#ifdef HAVE_STRERROR
return (strerror(errnum));
+#else
+ extern int sys_nerr;
+ extern const char *const sys_errlist[];
+ static char ebuf[20];
+
+ if ((unsigned int)errnum < sys_nerr)
+ return ((char *)sys_errlist[errnum]);
+ (void)sprintf(ebuf, "Unknown error: %d", errnum);
+ return(ebuf);
+#endif
}
void
@@ -166,7 +186,7 @@ pcap_close(pcap_t *p)
if (p->fd >= 0)
close(p->fd);
if (p->sf.rfile != NULL) {
- fclose(p->sf.rfile);
+ (void)fclose(p->sf.rfile);
if (p->sf.base != NULL)
free(p->sf.base);
} else if (p->buffer != NULL)