From: guy Date: Wed, 15 Dec 2004 00:25:08 +0000 (+0000) Subject: Put the FDDI padding (if any) into the pcap_t structure on platforms X-Git-Tag: libpcap-0.9.1~120 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/3573dfdacc1a0b461a679f9d9ba388ea4e943979 Put the FDDI padding (if any) into the pcap_t structure on platforms that require it, and make pcap_fddipad private to the code generator, as that's the only place that needs it (ideally, all *its* state should be local as well). This makes opening an FDDI device, on platforms where the padding is supplied as part of the packet, and opening other types of devices or opening savefiles in the same program work better, as you don't have to be sure you compile the filter for a given pcap_t before opening the next pcap_t. --- diff --git a/gencode.c b/gencode.c index d37f9841..3f8d3be4 100644 --- a/gencode.c +++ b/gencode.c @@ -21,7 +21,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.212 2004-11-06 22:57:28 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.213 2004-12-15 00:25:08 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -102,9 +102,7 @@ static u_int orig_linktype = -1U, orig_nl = -1U, orig_nl_nosnap = -1U; /* XXX */ #ifdef PCAP_FDDIPAD -int pcap_fddipad = PCAP_FDDIPAD; -#else -int pcap_fddipad; +static int pcap_fddipad; #endif /* VARARGS */ @@ -123,7 +121,7 @@ bpf_error(const char *fmt, ...) /* NOTREACHED */ } -static void init_linktype(int); +static void init_linktype(pcap_t *); static int alloc_reg(void); static void free_reg(int); @@ -133,8 +131,10 @@ static struct block *root; /* * We divy out chunks of memory rather than call malloc each time so * we don't have to worry about leaking memory. It's probably - * not a big deal if all this memory was wasted but it this ever + * not a big deal if all this memory was wasted but if this ever * goes into a library that would probably not be a good idea. + * + * XXX - this *is* in a library.... */ #define NCHUNKS 16 #define CHUNK0SIZE 1024 @@ -341,7 +341,7 @@ pcap_compile(pcap_t *p, struct bpf_program *program, } lex_init(buf ? buf : ""); - init_linktype(pcap_datalink(p)); + init_linktype(p); (void)pcap_parse(); if (n_errors) @@ -679,10 +679,13 @@ static u_int off_nl_nosnap; static int linktype; static void -init_linktype(type) - int type; +init_linktype(p) + pcap_t *p; { - linktype = type; + linktype = pcap_datalink(p); +#ifdef PCAP_FDDIPAD + pcap_fddipad = p->fddipad; +#endif /* * Assume it's not raw ATM with a pseudo-header, for now. @@ -699,7 +702,7 @@ init_linktype(type) orig_nl = -1; orig_nl_nosnap = -1; - switch (type) { + switch (linktype) { case DLT_ARCNET: off_linktype = 2; diff --git a/pcap-bpf.c b/pcap-bpf.c index 697703c0..f1de34de 100644 --- a/pcap-bpf.c +++ b/pcap-bpf.c @@ -20,7 +20,7 @@ */ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.83 2004-12-14 23:55:30 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.84 2004-12-15 00:25:09 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -229,10 +229,7 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user) #define bhp ((struct bpf_hdr *)bp) ep = bp + cc; #ifdef PCAP_FDDIPAD - if (pc->linktype == DLT_FDDI) - pad = pcap_fddipad; - else - pad = 0; + pad = p->fddipad; #endif while (bp < ep) { register int caplen, hdrlen; @@ -266,7 +263,7 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_handler callback, u_char *user) * #ifdef PCAP_FDDIPAD * Note: the filter code was generated assuming - * that pcap_fddipad was the amount of padding + * that p->fddipad was the amount of padding * before the header, as that's what's required * in the kernel, so we run the filter before * skipping that padding. @@ -727,6 +724,12 @@ pcap_open_live(const char *device, int snaplen, int promisc, int to_ms, v = DLT_CHDLC; break; } +#endif +#ifdef PCAP_FDDIPAD + if (v == DLT_FDDI) + p->fddipad = PCAP_FDDIPAD: + else + p->fddipad = 0; #endif p->linktype = v; diff --git a/pcap-int.h b/pcap-int.h index d481f028..6f9c7764 100644 --- a/pcap-int.h +++ b/pcap-int.h @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.65 2004-10-19 07:06:12 guy Exp $ (LBL) + * @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.66 2004-12-15 00:25:09 guy Exp $ (LBL) */ #ifndef pcap_int_h @@ -112,6 +112,10 @@ struct pcap { int break_loop; /* flag set to force break from packet-reading loop */ +#ifdef PCAP_FDDIPAD + int fddipad; +#endif + struct pcap_sf sf; struct pcap_md md; @@ -284,9 +288,6 @@ int add_or_find_if(pcap_if_t **, pcap_if_t **, const char *, u_int, char *pcap_win32strerror(void); #endif -/* XXX */ -extern int pcap_fddipad; - int install_bpf_program(pcap_t *, struct bpf_program *); int pcap_strcasecmp(const char *, const char *); diff --git a/pcap-pf.c b/pcap-pf.c index cd3ee97b..fe21c803 100644 --- a/pcap-pf.c +++ b/pcap-pf.c @@ -24,7 +24,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.89 2004-12-15 00:05:48 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/pcap-pf.c,v 1.90 2004-12-15 00:25:09 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -129,10 +129,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) */ n = 0; #ifdef PCAP_FDDIPAD - if (pc->linktype == DLT_FDDI) - pad = pcap_fddipad; - else - pad = 0; + pad = p->fddipad; #endif while (cc > 0) { /* @@ -194,7 +191,7 @@ pcap_read_pf(pcap_t *pc, int cnt, pcap_handler callback, u_char *user) * #ifdef PCAP_FDDIPAD * Note: the filter code was generated assuming - * that pcap_fddipad was the amount of padding + * that p->fddipad was the amount of padding * before the header, as that's what's required * in the kernel, so we run the filter before * skipping that padding. @@ -450,9 +447,13 @@ your system may not be properly configured; see the packetfilter(4) man page\n", } /* set truncation */ #ifdef PCAP_FDDIPAD - if (p->linktype == DLT_FDDI) + if (p->linktype == DLT_FDDI) { + p->fddipad = PCAP_FDDIPAD: + /* packetfilter includes the padding in the snapshot */ - snaplen += pcap_fddipad; + snaplen += PCAP_FDDIPAD; + } else + p->fddipad = 0; #endif if (ioctl(p->fd, EIOCTRUNCATE, (caddr_t)&snaplen) < 0) { snprintf(ebuf, PCAP_ERRBUF_SIZE, "EIOCTRUNCATE: %s", diff --git a/savefile.c b/savefile.c index c20466fe..f4497376 100644 --- a/savefile.c +++ b/savefile.c @@ -30,7 +30,7 @@ #ifndef lint static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.115 2004-12-09 19:03:37 guy Exp $ (LBL)"; + "@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.116 2004-12-15 00:25:09 guy Exp $ (LBL)"; #endif #ifdef HAVE_CONFIG_H @@ -766,8 +766,8 @@ pcap_fopen_offline(FILE *fp, char *errbuf) p->sf.version_major = hdr.version_major; p->sf.version_minor = hdr.version_minor; #ifdef PCAP_FDDIPAD - /* XXX padding only needed for kernel fcode */ - pcap_fddipad = 0; + /* Padding only needed for live capture fcode */ + p->fddipad = 0; #endif /*