]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Default to first interface from pcap_findalldevs()
[tcpdump] / tcpdump.c
index fcba6671f2765d2fba32c679045caed46d26dc71..a0c627c66361cb9cc2f2fd3f76fbc31db2fc9c98 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -56,10 +56,6 @@ The Regents of the University of California.  All rights reserved.\n";
 
 #include <netdissect-stdinc.h>
 
-#ifdef _WIN32
-#define off_t long
-#endif /* _WIN32 */
-
 #ifdef USE_LIBSMI
 #include <smi.h>
 #endif
@@ -1295,7 +1291,12 @@ main(int argc, char **argv)
                 * We're doing a live capture.
                 */
                if (device == NULL) {
+#ifdef HAVE_PCAP_FINDALLDEVS
+                       if (pcap_findalldevs(&devpointer, ebuf) >= 0 && devpointer != NULL)
+                               device = devpointer->name;
+#else /* HAVE_PCAP_FINDALLDEVS */
                        device = pcap_lookupdev(ebuf);
+#endif
                        if (device == NULL)
                                error("%s", ebuf);
                }
@@ -1841,14 +1842,14 @@ child_cleanup(int signo _U_)
 static void
 info(register int verbose)
 {
-       struct pcap_stat stat;
+       struct pcap_stat stats;
 
        /*
         * Older versions of libpcap didn't set ps_ifdrop on some
         * platforms; initialize it to 0 to handle that.
         */
-       stat.ps_ifdrop = 0;
-       if (pcap_stats(pd, &stat) < 0) {
+       stats.ps_ifdrop = 0;
+       if (pcap_stats(pd, &stats) < 0) {
                (void)fprintf(stderr, "pcap_stats: %s\n", pcap_geterr(pd));
                infoprint = 0;
                return;
@@ -1863,21 +1864,21 @@ info(register int verbose)
                fputs(", ", stderr);
        else
                putc('\n', stderr);
-       (void)fprintf(stderr, "%u packet%s received by filter", stat.ps_recv,
-           PLURAL_SUFFIX(stat.ps_recv));
+       (void)fprintf(stderr, "%u packet%s received by filter", stats.ps_recv,
+           PLURAL_SUFFIX(stats.ps_recv));
        if (!verbose)
                fputs(", ", stderr);
        else
                putc('\n', stderr);
-       (void)fprintf(stderr, "%u packet%s dropped by kernel", stat.ps_drop,
-           PLURAL_SUFFIX(stat.ps_drop));
-       if (stat.ps_ifdrop != 0) {
+       (void)fprintf(stderr, "%u packet%s dropped by kernel", stats.ps_drop,
+           PLURAL_SUFFIX(stats.ps_drop));
+       if (stats.ps_ifdrop != 0) {
                if (!verbose)
                        fputs(", ", stderr);
                else
                        putc('\n', stderr);
                (void)fprintf(stderr, "%u packet%s dropped by interface\n",
-                   stat.ps_ifdrop, PLURAL_SUFFIX(stat.ps_ifdrop));
+                   stats.ps_ifdrop, PLURAL_SUFFIX(stats.ps_ifdrop));
        } else
                putc('\n', stderr);
        infoprint = 0;
@@ -2199,17 +2200,13 @@ RETSIGTYPE requestinfo(int signo _U_)
 void CALLBACK verbose_stats_dump (UINT timer_id _U_, UINT msg _U_, DWORD_PTR arg _U_,
                                  DWORD_PTR dw1 _U_, DWORD_PTR dw2 _U_)
 {
-       struct pcap_stat stat;
-
-       if (infodelay == 0 && pcap_stats(pd, &stat) >= 0)
+       if (infodelay == 0)
                fprintf(stderr, "Got %u\r", packets_captured);
 }
 #elif defined(HAVE_ALARM)
 static void verbose_stats_dump(int sig _U_)
 {
-       struct pcap_stat stat;
-
-       if (infodelay == 0 && pcap_stats(pd, &stat) >= 0)
+       if (infodelay == 0)
                fprintf(stderr, "Got %u\r", packets_captured);
        alarm(1);
 }