From a6bce8883c0f9dd7fee0eb03667f57b40b1d9dab Mon Sep 17 00:00:00 2001 From: fenner Date: Tue, 3 Apr 2001 04:18:09 +0000 Subject: Virgin import of tcpdump.org libpcap v0.6.2 --- contrib/libpcap/pcap.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'contrib/libpcap/pcap.c') diff --git a/contrib/libpcap/pcap.c b/contrib/libpcap/pcap.c index 3b857f6..9f32721 100644 --- a/contrib/libpcap/pcap.c +++ b/contrib/libpcap/pcap.c @@ -33,7 +33,11 @@ #ifndef lint static const char rcsid[] = - "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.29.1.1 1999/10/07 23:46:40 mcr Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.36 2000/12/16 10:43:31 guy Exp $ (LBL)"; +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" #endif #include @@ -43,7 +47,6 @@ static const char rcsid[] = #include #include -#include "gnuc.h" #ifdef HAVE_OS_PROTO_H #include "os-proto.h" #endif @@ -180,27 +183,44 @@ pcap_strerror(int errnum) if ((unsigned int)errnum < sys_nerr) return ((char *)sys_errlist[errnum]); - (void)sprintf(ebuf, "Unknown error: %d", errnum); + (void)snprintf(ebuf, sizeof ebuf, "Unknown error: %d", errnum); return(ebuf); #endif } +pcap_t * +pcap_open_dead(int linktype, int snaplen) +{ + pcap_t *p; + + p = malloc(sizeof(*p)); + if (p == NULL) + return NULL; + memset (p, 0, sizeof(*p)); + p->fd = -1; + p->snapshot = snaplen; + p->linktype = linktype; + return p; +} + void pcap_close(pcap_t *p) { /*XXX*/ - if (p->fd >= 0) + if (p->fd >= 0) { +#ifdef linux + pcap_close_linux(p); +#endif close(p->fd); + } if (p->sf.rfile != NULL) { - (void)fclose(p->sf.rfile); + if (p->sf.rfile != stdin) + (void)fclose(p->sf.rfile); if (p->sf.base != NULL) free(p->sf.base); } else if (p->buffer != NULL) free(p->buffer); -#ifdef linux - if (p->md.device != NULL) - free(p->md.device); -#endif + pcap_freecode(&p->fcode); free(p); } -- cgit v1.1