]> The Tcpdump Group git mirrors - libpcap/commitdiff
Only set the cleanup and set/get nonblocking mode handlers to the
authorguy <guy>
Tue, 16 Sep 2008 18:43:02 +0000 (18:43 +0000)
committerguy <guy>
Tue, 16 Sep 2008 18:43:02 +0000 (18:43 +0000)
zerocopy handlers when we decide to use zerocopy mode.  That means they
don't need to check whether zerocopy mode is being used.

pcap-bpf.c

index faca5c210ca3018c36ff7ab6a18a75b1cb0bb57f..6ec6515fb7c7202c50596cbcb5945d9a0b4fe4f1 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.99.2.16 2008-09-16 17:20:50 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-bpf.c,v 1.99.2.17 2008-09-16 18:43:02 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -205,21 +205,14 @@ pcap_setnonblock_zbuf(pcap_t *p, int nonblock, char *errbuf)
  * pcap_cleanup_live_common.
  */
 static void
  * pcap_cleanup_live_common.
  */
 static void
-pcap_close_zbuf(pcap_t *p)
+pcap_cleanup_zbuf(pcap_t *p)
 {
        /*
 {
        /*
-        * Check to see if this pcap instance was using the zerocopy buffer
-        * mode.  If it was, delete the mappings.  Note that p->buffer
-        * gets initialized to one of the mmaped regions in this case, so
-        * do not try and free it directly.
-        *
-        * If the regular buffer mode was selected, then it is safe to free
-        * this memory.
+        * Delete the mappings.  Note that p->buffer gets initialized to one
+        * of the mmapped regions in this case, so do not try and free it
+        * directly; null it out so that pcap_cleanup_live_common() doesn't
+        * try to free it.
         */
         */
-       if (p->md.zerocopy == 0) {
-               pcap_cleanup_live_common(p);
-               return;
-       }
        if (p->md.zbuf1 != MAP_FAILED && p->md.zbuf1 != NULL)
                (void) munmap(p->md.zbuf1, p->md.zbufsize);
        if (p->md.zbuf2 != MAP_FAILED && p->md.zbuf2 != NULL)
        if (p->md.zbuf1 != MAP_FAILED && p->md.zbuf1 != NULL)
                (void) munmap(p->md.zbuf1, p->md.zbufsize);
        if (p->md.zbuf2 != MAP_FAILED && p->md.zbuf2 != NULL)
@@ -398,11 +391,6 @@ pcap_create(const char *device, char *ebuf)
                return (NULL);
 
        p->activate_op = pcap_activate_bpf;
                return (NULL);
 
        p->activate_op = pcap_activate_bpf;
-#ifdef HAVE_ZEROCOPY_BPF
-       p->cleanup_op = pcap_close_zbuf;
-       p->setnonblock_op = pcap_setnonblock_zbuf;
-       p->getnonblock_op = pcap_getnonblock_zbuf;
-#endif
        p->can_set_rfmon_op = pcap_can_set_rfmon_bpf;
        return (p);
 }
        p->can_set_rfmon_op = pcap_can_set_rfmon_bpf;
        return (p);
 }
@@ -1473,6 +1461,14 @@ pcap_activate_bpf(pcap_t *p)
                 */
                p->md.zerocopy = 1;
 
                 */
                p->md.zerocopy = 1;
 
+               /*
+                * Set the cleanup and set/get nonblocking mode ops
+                * as appropriate for zero-copy mode.
+                */
+               p->cleanup_op = pcap_cleanup_zbuf;
+               p->setnonblock_op = pcap_setnonblock_zbuf;
+               p->getnonblock_op = pcap_getnonblock_zbuf;
+
                /*
                 * How to pick a buffer size: first, query the maximum buffer
                 * size supported by zero-copy.  This also lets us quickly
                /*
                 * How to pick a buffer size: first, query the maximum buffer
                 * size supported by zero-copy.  This also lets us quickly