tcpdump mailing list archives
setting rcvbuf
From: John Heffner <jheffner () psc edu>
Date: Tue, 15 Jun 2004 17:49:21 -0400 (EDT)
I've found that on my linux machines, setting the rcvbuf on the packet socket bigger helps to reduce drops at high rates. I implemented the following, though I'm not sure how this works on BSD and other UNIXes. I'm also only guessing that pcap_setbuff has a similar meaning under windows and that overloading it makes sense. Does this seem like a reasonable thing to do? Thanks, -John Index: tcpdump.c =================================================================== RCS file: /tcpdump/master/tcpdump/tcpdump.c,v retrieving revision 1.243 diff -U3 -r1.243 tcpdump.c --- tcpdump.c 15 Jun 2004 00:00:04 -0000 1.243 +++ tcpdump.c 15 Jun 2004 21:41:20 -0000 @@ -287,13 +287,8 @@ * Set up flags that might or might not be supported depending on the * version of libpcap we're using. */ -#ifdef WIN32 #define B_FLAG "B:" #define B_FLAG_USAGE " [ -B size ]" -#else /* WIN32 */ -#define B_FLAG -#define B_FLAG_USAGE -#endif /* WIN32 */ #ifdef HAVE_PCAP_FINDALLDEVS #ifndef HAVE_PCAP_IF_T @@ -413,8 +408,8 @@ int devnum; #endif int status; -#ifdef WIN32 u_int UserBufferSize = 1000000; +#ifdef WIN32 if(wsockinit() != 0) return 1; #endif /* WIN32 */ @@ -459,13 +454,11 @@ ++Aflag; break; -#ifdef WIN32 case 'B': UserBufferSize = atoi(optarg)*1024; if (UserBufferSize < 0) error("invalid packet buffer size %s", optarg); break; -#endif /* WIN32 */ case 'c': cnt = atoi(optarg); @@ -828,12 +821,10 @@ if (setgid(getgid()) != 0 || setuid(getuid()) != 0) fprintf(stderr, "Warning: setgid/setuid failed !\n"); #endif /* WIN32 */ -#ifdef WIN32 if(UserBufferSize != 1000000) if(pcap_setbuff(pd, UserBufferSize)==-1){ error("%s", pcap_geterr(pd)); } -#endif /* WIN32 */ if (Lflag) show_dlts_and_exit(pd); if (gndo->ndo_dlt >= 0) { Index: pcap-win32.c =================================================================== RCS file: /tcpdump/master/libpcap/pcap-win32.c,v retrieving revision 1.22 diff -U3 -r1.22 pcap-win32.c --- pcap-win32.c 7 Jun 2004 13:27:46 -0000 1.22 +++ pcap-win32.c 15 Jun 2004 21:49:45 -0000 @@ -717,24 +717,6 @@ return 0; } -/* Set the dimension of the kernel-level capture buffer */ -int -pcap_setbuff(pcap_t *p, int dim) -{ - if (p->adapter==NULL) - { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "The kernel buffer size cannot be set while reading from a file"); - return -1; - } - - if(PacketSetBuff(p->adapter,dim)==FALSE) - { - snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer"); - return -1; - } - return 0; -} - /*set the minimum amount of data that will release a read call*/ int pcap_setmintocopy(pcap_t *p, int size) Index: pcap.c =================================================================== RCS file: /tcpdump/master/libpcap/pcap.c,v retrieving revision 1.74 diff -U3 -r1.74 pcap.c --- pcap.c 24 Mar 2004 19:50:54 -0000 1.74 +++ pcap.c 15 Jun 2004 21:49:45 -0000 @@ -44,6 +44,7 @@ #include <pcap-stdinc.h> #else /* WIN32 */ #include <sys/types.h> +#include <sys/socket.h> #endif /* WIN32 */ #include <stdio.h> @@ -520,6 +521,28 @@ #endif } +/* Set the dimension of the kernel-level capture buffer */ +int +pcap_setbuff(pcap_t *p, int dim) +{ +#ifndef WIN32 + return setsockopt(p->fd, SOL_SOCKET, SO_RCVBUF, &dim, sizeof (dim)); +#else + if (p->adapter==NULL) + { + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "The kernel buffer size cannot be set while reading from a file"); + return -1; + } + + if(PacketSetBuff(p->adapter,dim)==FALSE) + { + snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer"); + return -1; + } + return 0; +#endif +} + #ifndef WIN32 int pcap_get_selectable_fd(pcap_t *p) Index: pcap.h =================================================================== RCS file: /tcpdump/master/libpcap/pcap.h,v retrieving revision 1.50 diff -U3 -r1.50 pcap.h --- pcap.h 23 Mar 2004 19:18:07 -0000 1.50 +++ pcap.h 15 Jun 2004 21:49:45 -0000 @@ -207,6 +207,7 @@ /* XXX */ FILE *pcap_file(pcap_t *); int pcap_fileno(pcap_t *); +int pcap_setbuff(pcap_t *p, int dim); pcap_dumper_t *pcap_dump_open(pcap_t *, const char *); int pcap_dump_flush(pcap_dumper_t *); @@ -230,7 +231,6 @@ * Win32 definitions */ -int pcap_setbuff(pcap_t *p, int dim); int pcap_setmode(pcap_t *p, int mode); int pcap_setmintocopy(pcap_t *p, int size); - This is the tcpdump-workers list. Visit https://lists.sandelman.ca/ to unsubscribe.
Current thread:
- setting rcvbuf John Heffner (Jun 15)
- Re: setting rcvbuf Guy Harris (Jun 15)
- Re: setting rcvbuf John Heffner (Jun 16)
- Re: setting rcvbuf Guy Harris (Jun 15)