From: Guy Harris Date: Sun, 26 Jul 2009 22:44:31 +0000 (-0700) Subject: Clean up per-packet output a bit; don't output a blank line if no X-Git-Tag: libpcap-1.1.0~100 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/c3c51e58e50539bbfd84d3492472566f44cf4bce Clean up per-packet output a bit; don't output a blank line if no packets were seen, but do put the "."s on a separate line - which should all come out in a burst, so don't fflush() after each one, let the newline at the end do that. Report POLLNVAL for poll(). When not using select() or poll(), loop forever doing pcap_dispatch(), rather than just using pcap_loop(), so you see what happens for each delivered batch of packets. --- diff --git a/selpolltest.c b/selpolltest.c index 03e9395c..f80fb1f6 100644 --- a/selpolltest.c +++ b/selpolltest.c @@ -182,7 +182,9 @@ main(int argc, char **argv) (u_char *)&packet_count); if (status < 0) break; - printf("\n%d packets seen, %d packets counted after select returns\n", + if (packet_count != 0) + putchar('\n'); /* finish line of .'s */ + printf("%d packets seen, %d packets counted after select returns\n", status, packet_count); } } @@ -215,24 +217,35 @@ main(int argc, char **argv) else printf("no exceptional condition, "); if (fd.revents & POLLHUP) - printf("disconnect\n"); + printf("disconnect, "); else - printf("no disconnect\n"); + printf("no disconnect, "); + if (fd.revents & POLLNVAL) + printf("invalid\n"); + else + printf("not invalid\n"); } packet_count = 0; status = pcap_dispatch(pd, -1, printme, (u_char *)&packet_count); if (status < 0) break; - printf("\n%d packets seen, %d packets counted after poll returns\n", + if (packet_count != 0) + putchar('\n'); /* finish line of .'s */ + printf("%d packets seen, %d packets counted after poll returns\n", status, packet_count); } } } else { - packet_count = 0; - status = pcap_loop(pd, -1, printme, (u_char *)&packet_count); - if (status >= 0) { - printf("\n%d packets seen, %d packets counted by pcap_loop\n", + for (;;) { + packet_count = 0; + status = pcap_dispatch(pd, -1, printme, + (u_char *)&packet_count); + if (status < 0) + break; + if (packet_count != 0) + putchar('\n'); /* finish line of .'s */ + printf("%d packets seen, %d packets counted after pcap_dispatch returns\n", status, packet_count); } } @@ -262,7 +275,6 @@ printme(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) int *counterp = (int *)user; printf("."); - fflush(stdout); (*counterp)++; }