*/
#include <config.h>
+#ifndef TCPDUMP_CONFIG_H_
+#error "The included config.h header is not from the tcpdump build."
+#endif
#include "netdissect-stdinc.h"
#include "netdissect.h"
#include "interface.h"
#include "addrtoname.h"
-#include "pcap-missing.h"
#include "ascii_strcasecmp.h"
#include "print.h"
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;
char **endp, int64_t minval, int64_t maxval, int base);
static void (*setsignal (int sig, void (*func)(int)))(int);
static void cleanup(int);
+#if defined(HAVE_FORK) || defined(HAVE_VFORK)
static void child_cleanup(int);
+#endif
static void print_version(FILE *);
static void print_usage(FILE *);
} 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) {
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;
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();
#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);
capdns = capdns_setup();
#endif /* HAVE_CASPER */
+ // Both localnet and netmask are in network byte order.
init_print(ndo, localnet, netmask);
#ifndef _WIN32
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) {
/*
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));
}
dump_info = (struct dump_info *)user;
- if (packets_captured <= packets_skipped)
+ if (packets_captured <= packets_to_skip)
return;
/*
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);
++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;