]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
tcpdump.c: Fix a warning when HAVE_FORK and HAVE_VFORK are not defined
[tcpdump] / tcpdump.c
index 31a816707f1ef1c739ee123a4a153ba4d7bfbcf9..d2af6e6908b45140df68e5452c06281cbf7bc34e 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -34,6 +34,9 @@
  */
 
 #include <config.h>
+#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;
@@ -223,7 +225,9 @@ static int64_t parse_int64(const char *argname, const char *string,
     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 *);
 
@@ -1346,6 +1350,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 +2064,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 +2107,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 +2379,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 +2398,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 +2713,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 +2802,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 +3208,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 +3340,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 +3362,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;