diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-12-14 23:54:21 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-12-14 23:54:21 -0800 |
commit | 86b47f156ccc8be9b7143e1bc04d7d8fbf995383 (patch) | |
tree | 20bed4ff90845f93c81273d7b6ef4a4a16114036 /pcap-linux.c | |
parent | 1a52c9a05758d162e331dc93d60c51ebeb7b0f55 (diff) |
Add a PACKET_COUNT_IS_UNLIMITED() to test for a packet count <= 0.
In read routines, a packet count <= 0 means "keep supplying packets
until you run out of packets in the buffer", and it means "keep supply
packets until the loop is broken out of or you get an error" in
pcap_loop().
Use the macro in all tests for that, so the right test is always done
(i.e., a count of 0 means "unlimited", not "supply zero packets"); this
fixes some cases where we weren't doing the right test (and hopefully
encourages programmers to use it and get the test right in new modules).
Diffstat (limited to 'pcap-linux.c')
-rw-r--r-- | pcap-linux.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/pcap-linux.c b/pcap-linux.c index 565abd3b..7a05ff29 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -4333,7 +4333,7 @@ pcap_read_linux_mmap_v1(pcap_t *handle, int max_packets, pcap_handler callback, /* non-positive values of max_packets are used to require all * packets currently available in the ring */ - while ((pkts < max_packets) || (max_packets <= 0)) { + while ((pkts < max_packets) || PACKET_COUNT_IS_UNLIMITED(max_packets)) { union thdr h; h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER); @@ -4391,7 +4391,7 @@ pcap_read_linux_mmap_v2(pcap_t *handle, int max_packets, pcap_handler callback, /* non-positive values of max_packets are used to require all * packets currently available in the ring */ - while ((pkts < max_packets) || (max_packets <= 0)) { + while ((pkts < max_packets) || PACKET_COUNT_IS_UNLIMITED(max_packets)) { union thdr h; h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER); @@ -4460,7 +4460,7 @@ pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback, /* non-positive values of max_packets are used to require all * packets currently available in the ring */ - while ((pkts < max_packets) || (max_packets <= 0)) { + while ((pkts < max_packets) || PACKET_COUNT_IS_UNLIMITED(max_packets)) { if (handlep->current_packet == NULL) { h.raw = pcap_get_ring_frame(handle, TP_STATUS_USER); if (!h.raw) @@ -4471,7 +4471,7 @@ pcap_read_linux_mmap_v3(pcap_t *handle, int max_packets, pcap_handler callback, } int packets_to_read = handlep->packets_left; - if (max_packets > 0 && packets_to_read > max_packets) { + if (!PACKET_COUNT_IS_UNLIMITED(max_packets) && packets_to_read > max_packets) { packets_to_read = max_packets; } |