]> The Tcpdump Group git mirrors - libpcap/commitdiff
Put the FDDI padding (if any) into the pcap_t structure on platforms
authorguy <guy>
Wed, 15 Dec 2004 00:25:08 +0000 (00:25 +0000)
committerguy <guy>
Wed, 15 Dec 2004 00:25:08 +0000 (00:25 +0000)
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.

gencode.c
pcap-bpf.c
pcap-int.h
pcap-pf.c
savefile.c

index d37f9841db9a2cbe19cd1a412026408e322e8fa3..3f8d3be443ab6d913698a97c95fe94cbe3a4e99f 100644 (file)
--- 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;
index 697703c09a6a756f1db4cb216237b2a48e684254..f1de34de252c66ea6fb2bc5b2cabaf255e88a257 100644 (file)
@@ -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;
 
index d481f02831a7f7b80a224dd9ced94d7fe8bfba07..6f9c776483188ea84b52d4cc1e3419e122ad7328 100644 (file)
@@ -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 *);
index cd3ee97b73745e827827543b3d4b59bf67a5c5c4..fe21c8033e0afdfe03d68cff3673effa27ad6986 100644 (file)
--- 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",
index c20466fe9484428d7ba947f6dda1341abe739777..f44973769b30b1b8b06142e7e14b9c20337f30db 100644 (file)
@@ -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
 
        /*