]> The Tcpdump Group git mirrors - libpcap/commitdiff
Use PACKET_COUNT_IS_UNLIMITED() in pcap_offline_read().
authorGuy Harris <[email protected]>
Wed, 3 Nov 2021 05:37:13 +0000 (22:37 -0700)
committerGuy Harris <[email protected]>
Sun, 20 Feb 2022 23:25:49 +0000 (15:25 -0800)
That's what should always be used to check whether a packet count
argument means "give me all the packets you have".

Check it first, so we don't compare the packet count against a zero or
negative value.

(cherry picked from commit 56c60dd660297b5cf02afcb9fdc4f92689de0353)

savefile.c

index 9e6a7deb6f891fece9ec955709efa3c1489ae92e..acd915cf73057912fe7a6dffc541fb6e94648529 100644 (file)
@@ -663,7 +663,8 @@ pcap_offline_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
                if ((fcode = p->fcode.bf_insns) == NULL ||
                    pcap_filter(fcode, data, h.len, h.caplen)) {
                        (*callback)(user, &h, data);
-                       if (++n >= cnt && cnt > 0)
+                       n++;    /* count the packet */
+                       if (!PACKET_COUNT_IS_UNLIMITED(cnt) && n >= cnt)
                                break;
                }
        }