* savefile header to control the size of the buffer they allocate,
* so a size of, say, 2^31-1 might not work well.
*
- * XXX - does it need to be bigger still?
+ * XXX - does it need to be bigger still? Note that, for versions of
+ * libpcap with pcap_create()/pcap_activate(), if no -s flag is specified
+ * or -s 0 is specified, we won't set the snapshot length at all, and will
+ * let libpcap choose a snapshot length; newer versions may choose a bigger
+ * value than 262144 for D-Bus, for example.
*/
#define MAXIMUM_SNAPLEN 262144
-/*
- * The default snapshot length is the maximum.
- */
-#define DEFAULT_SNAPLEN MAXIMUM_SNAPLEN
-
#define ESRC(ep) ((ep)->ether_shost)
#define EDST(ep) ((ep)->ether_dhost)
supports_monitor_mode = 1;
else
supports_monitor_mode = 0;
- status = pcap_set_snaplen(pc, ndo->ndo_snaplen);
- if (status != 0)
- error("%s: Can't set snapshot length: %s",
- device, pcap_statustostr(status));
+ if (ndo->ndo_snaplen != 0) {
+ /*
+ * A snapshot length was explicitly specified;
+ * use it.
+ */
+ status = pcap_set_snaplen(pc, ndo->ndo_snaplen);
+ if (status != 0)
+ error("%s: Can't set snapshot length: %s",
+ device, pcap_statustostr(status));
+ }
status = pcap_set_promisc(pc, !pflag);
if (status != 0)
error("%s: Can't set promiscuous mode: %s",
#endif /* HAVE_PCAP_SETDIRECTION */
#else /* HAVE_PCAP_CREATE */
*ebuf = '\0';
+ /*
+ * If no snapshot length was specified, or a length of 0 was
+ * specified, default to 256KB.
+ */
+ if (ndo->ndo_snaplen == 0)
+ ndo->ndo_snaplen = 262144;
pc = pcap_open_live(device, ndo->ndo_snaplen, !pflag, 1000, ebuf);
if (pc == NULL) {
/*
memset(ndo, 0, sizeof(*ndo));
ndo_set_function_pointers(ndo);
- ndo->ndo_snaplen = DEFAULT_SNAPLEN;
cnt = -1;
device = NULL;
if (optarg == end || *end != '\0'
|| ndo->ndo_snaplen < 0 || ndo->ndo_snaplen > MAXIMUM_SNAPLEN)
error("invalid snaplen %s", optarg);
- else if (ndo->ndo_snaplen == 0)
- ndo->ndo_snaplen = MAXIMUM_SNAPLEN;
break;
case 'S':
}
/*
- * Let user own process after socket has been opened.
+ * Let user own process after capture device has
+ * been opened.
*/
#ifndef _WIN32
if (setgid(getgid()) != 0 || setuid(getuid()) != 0)
}
i = pcap_snapshot(pd);
if (ndo->ndo_snaplen < i) {
- warning("snaplen raised from %d to %d", ndo->ndo_snaplen, i);
+ if (ndo->ndo_snaplen != 0)
+ warning("snaplen raised from %d to %d", ndo->ndo_snaplen, i);
+ ndo->ndo_snaplen = i;
+ } else if (ndo->ndo_snaplen > i) {
+ warning("snaplen lowered from %d to %d", ndo->ndo_snaplen, i);
ndo->ndo_snaplen = i;
}
if(ndo->ndo_fflag != 0) {