diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-06-01 17:58:28 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-06-01 17:58:28 -0700 |
commit | 42c3865d71a3d3ad3fc61ee382ad3b5113d40552 (patch) | |
tree | 669532521e73c10b2f1e520bf0c1417df255e68c /pcap-win32.c | |
parent | 1a6b088a88886eac782008f37a7219a32b86da45 (diff) |
Make the checks and adjustment of the snapshot length module-dependent.
Also, initialize the snapshot length to 0, meaning "not specified", so
that the default snapshot length, if not specified, is also
module-dependent.
That way, D-Bus has a maximum and default of 128MB, as that's the
maximum message size, but other capture devices have the current
MAXIMUM_SNAPLEN, so we can handle full-size D-Bus messages without
advertising an overly-large snapshot length for other devices,
potentially causing libpcap and programs using it or reading libpcap
files to allocate overly-large buffers for other capture devices.
Diffstat (limited to 'pcap-win32.c')
-rw-r--r-- | pcap-win32.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/pcap-win32.c b/pcap-win32.c index 984774cf..b81aae82 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -1003,6 +1003,17 @@ pcap_activate_win32(pcap_t *p) break; } + /* + * Turn a negative snapshot value (invalid), a snapshot value of + * 0 (unspecified), or a value bigger than the normal maximum + * value, into the maximum allowed value. + * + * If some application really *needs* a bigger snapshot + * length, we should just increase MAXIMUM_SNAPLEN. + */ + if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN) + p->snapshot = MAXIMUM_SNAPLEN; + /* Set promiscuous mode */ if (p->opt.promisc) { @@ -1074,13 +1085,14 @@ pcap_activate_win32(pcap_t *p) goto bad; } } - } - else + } else { + /* + * Dag Card + */ #ifdef HAVE_DAG_API - { - /* - * Dag Card - */ + /* + * We have DAG support. + */ LONG status; HKEY dagkey; DWORD lptype; @@ -1114,15 +1126,18 @@ pcap_activate_win32(pcap_t *p) while(FALSE); - p->snapshot = PacketSetSnapLen(p->adapter, snaplen); + p->snapshot = PacketSetSnapLen(p->adapter, p->snapshot); /* Set the length of the FCS associated to any packet. This value * will be subtracted to the packet length */ pw->dag_fcs_bits = p->adapter->DagFcsLen; - } -#else - goto bad; +#else /* HAVE_DAG_API */ + /* + * No DAG support. + */ + goto bad; #endif /* HAVE_DAG_API */ + } PacketSetReadTimeout(p->adapter, p->opt.timeout); |