X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/dc1b49b1f6864a0cbe58bb203634763fb26aa8d1..9beea81f673bd6267a536d9132ca06a3d20a0235:/tcpdump.c diff --git a/tcpdump.c b/tcpdump.c index 31a81670..36c73259 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -34,6 +34,9 @@ */ #include +#ifndef TCPDUMP_CONFIG_H_ +#error "The included config.h header is not from the tcpdump build." +#endif #include "netdissect-stdinc.h" @@ -141,7 +144,6 @@ The Regents of the University of California. All rights reserved.\n"; #include "netdissect.h" #include "interface.h" #include "addrtoname.h" -#include "pcap-missing.h" #include "ascii_strcasecmp.h" #include "print.h" @@ -207,7 +209,7 @@ static int timeout = 1000; /* default timeout = 1000 ms = 1 s */ static int immediate_mode; #endif static int count_mode; -static u_int packets_skipped; +static u_int packets_to_skip; static int infodelay; static int infoprint; @@ -1346,6 +1348,11 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf) } else if (status == PCAP_ERROR_PERM_DENIED && *cp != '\0') error("%s: %s\n(%s)", device, pcap_statustostr(status), cp); +#ifdef PCAP_ERROR_CAPTURE_NOTSUP + else if (status == PCAP_ERROR_CAPTURE_NOTSUP && *cp != '\0') + error("%s: %s\n(%s)", device, + pcap_statustostr(status), cp); +#endif #ifdef __FreeBSD__ else if (status == PCAP_ERROR_RFMON_NOTSUP && strncmp(device, "wlan", 4) == 0) { @@ -2055,7 +2062,7 @@ main(int argc, char **argv) break; case OPTION_SKIP: - packets_skipped = parse_u_int("packet skip count", + packets_to_skip = parse_u_int("packet skip count", optarg, NULL, 0, INT_MAX, 0); break; @@ -2098,10 +2105,10 @@ main(int argc, char **argv) warning("-x[x] and -X[X] are mutually exclusive. -x[x] ignored."); if (cnt != -1) - if ((int)packets_skipped > (INT_MAX - cnt)) - // cnt + (int)packets_skipped used in pcap_loop() call + if ((int)packets_to_skip > (INT_MAX - cnt)) + // cnt + (int)packets_to_skip used in pcap_loop() call error("Overflow (-c count) %d + (--skip count) %d", cnt, - (int)packets_skipped); + (int)packets_to_skip); if (Dflag) show_devices_and_exit(); @@ -2370,7 +2377,11 @@ DIAG_ON_WARN_UNUSED_RESULT #ifdef HAVE_PCAP_SET_OPTIMIZER_DEBUG pcap_set_optimizer_debug(dflag); #endif - if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) + /* + * netmask is in network byte order, pcap_compile() takes it + * in host byte order. + */ + if (pcap_compile(pd, &fcode, cmdbuf, Oflag, ntohl(netmask)) < 0) error("%s", pcap_geterr(pd)); if (dflag) { bpf_dump(&fcode, dflag); @@ -2385,6 +2396,7 @@ DIAG_ON_WARN_UNUSED_RESULT capdns = capdns_setup(); #endif /* HAVE_CASPER */ + // Both localnet and netmask are in network byte order. init_print(ndo, localnet, netmask); #ifndef _WIN32 @@ -2699,7 +2711,7 @@ DIAG_ON_ASSIGN_ENUM do { status = pcap_loop(pd, - (cnt == -1 ? -1 : cnt + (int)packets_skipped), + (cnt == -1 ? -1 : cnt + (int)packets_to_skip), callback, pcap_userdata); if (WFileName == NULL) { /* @@ -2788,7 +2800,11 @@ DIAG_ON_ASSIGN_ENUM ndo->ndo_if_printer = get_if_printer(dlt); /* Free the old filter */ pcap_freecode(&fcode); - if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) + /* + * netmask is in network byte order, pcap_compile() takes it + * in host byte order. + */ + if (pcap_compile(pd, &fcode, cmdbuf, Oflag, ntohl(netmask)) < 0) error("%s", pcap_geterr(pd)); } @@ -3190,7 +3206,7 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s dump_info = (struct dump_info *)user; - if (packets_captured <= packets_skipped) + if (packets_captured <= packets_to_skip) return; /* @@ -3322,7 +3338,7 @@ dump_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) dump_info = (struct dump_info *)user; - if (packets_captured <= packets_skipped) + if (packets_captured <= packets_to_skip) return; pcap_dump((u_char *)dump_info->pdd, h, sp); @@ -3344,7 +3360,7 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) ++infodelay; - if (!count_mode && packets_captured > packets_skipped) + if (!count_mode && packets_captured > packets_to_skip) pretty_print_packet((netdissect_options *)user, h, sp, packets_captured); --infodelay;