]> The Tcpdump Group git mirrors - libpcap/commitdiff
For Linux non-mmapped captures, Linux bluetooth captures, and Irix
authorguy <guy>
Mon, 7 Apr 2008 03:57:32 +0000 (03:57 +0000)
committerguy <guy>
Mon, 7 Apr 2008 03:57:32 +0000 (03:57 +0000)
captures, set the socket buffer size to the value specified by
pcap_set_buffer_size() if a value was set.

Clean up if memory buffer allocation fails on Linux.

pcap-bt-linux.c
pcap-linux.c
pcap-snoop.c

index 0cb66248787301676e65e3dec88ecffddfb5cc64..e35181cc0076dbdbf3f94f6c3fed6801745c30d6 100644 (file)
@@ -33,7 +33,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.11 2008-04-04 19:37:45 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-bt-linux.c,v 1.12 2008-04-07 03:57:32 guy Exp $ (LBL)";
 #endif
  
 #ifdef HAVE_CONFIG_H
@@ -162,7 +162,7 @@ bt_activate(pcap_t* handle)
                snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
                        "Can't get Bluetooth device index from %s", 
                         handle->opt.source);
-               return -1;
+               return PCAP_ERROR;
        }
 
        /* Initialize some components of the pcap structure. */
@@ -186,7 +186,7 @@ bt_activate(pcap_t* handle)
        if (handle->fd < 0) {
                snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s",
                        errno, strerror(errno));
-               return -1;
+               return PCAP_ERROR;
        }
 
        handle->buffer = malloc(handle->bufsize);
@@ -230,12 +230,26 @@ bt_activate(pcap_t* handle)
                        handle->md.ifindex, errno, strerror(errno));
                goto close_fail;
        }
+
+       if (handle->opt.buffer_size == 0) {
+               /*
+                * Set the socket buffer size to the specified value.
+                */
+               if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
+                   &handle->opt.buffer_size,
+                   sizeof(handle->opt.buffer_size)) == -1) {
+                       snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+                                "SO_RCVBUF: %s", pcap_strerror(errno));
+                       goto close_fail;
+               }
+       }
+
        handle->selectable_fd = handle->fd;
        return 0;
 
 close_fail:
        close(handle->fd);
-       return -1;
+       return PCAP_ERROR;
 }
 
 static int
index 43e3a388a9ca455f359d819b5faed8144f133e99..e11f6011e349b39369a69b69527dc5a47bc025cc 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.142 2008-04-07 00:31:47 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-linux.c,v 1.143 2008-04-07 03:57:32 guy Exp $ (LBL)";
 #endif
 
 /*
@@ -553,12 +553,21 @@ pcap_activate_linux(pcap_t *handle)
                 * up and report our failure (ebuf is expected to be
                 * set by the functions above).
                 */
+               goto fail;
+       }
 
-               if (handle->md.device != NULL) {
-                       free(handle->md.device);
-                       handle->md.device = NULL;
+       if (handle->opt.buffer_size == 0) {
+               /*
+                * Set the socket buffer size to the specified value.
+                */
+               if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF,
+                   &handle->opt.buffer_size,
+                   sizeof(handle->opt.buffer_size)) == -1) {
+                       snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+                                "SO_RCVBUF: %s", pcap_strerror(errno));
+                       err = PCAP_ERROR;
+                       goto fail;
                }
-               return err;
        }
 
        /* Allocate the buffer */
@@ -567,7 +576,8 @@ pcap_activate_linux(pcap_t *handle)
        if (!handle->buffer) {
                snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
                         "malloc: %s", pcap_strerror(errno));
-               return PCAP_ERROR;
+               err = PCAP_ERROR;
+               goto fail;
        }
 
        /*
@@ -577,6 +587,14 @@ pcap_activate_linux(pcap_t *handle)
        handle->selectable_fd = handle->fd;
 
        return 0;
+
+fail:
+       close(handle->fd);
+       if (handle->md.device != NULL) {
+               free(handle->md.device);
+               handle->md.device = NULL;
+       }
+       return err;
 }
 
 /*
@@ -1775,7 +1793,7 @@ activate_new(pcap_t *handle)
        handle->bufsize = handle->snapshot;
 
        /* Save the socket FD in the pcap structure */
-       handle->fd       = sock_fd;
+       handle->fd = sock_fd;
 
        return 1;
 #else
index bbcf140957390313f0b7be3f45b3442a31962708..6cc9bb8f0c3fc9cc1b811cc5a213a63391ccce85 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.56 2008-04-04 19:37:45 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/libpcap/pcap-snoop.c,v 1.57 2008-04-07 03:57:32 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -234,7 +234,10 @@ pcap_activate_snoop(pcap_t *p)
                    pcap_strerror(errno));
                goto bad;
        }
-       v = 64 * 1024;
+       if (handle->opt.buffer_size != 0)
+               v = handle->opt.buffer_size;
+       else
+               v = 64 * 1024;  /* default to 64K buffer size */
        (void)setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&v, sizeof(v));
        /*
         * XXX hack - map device name to link layer type