]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
CARP: NDOize
[tcpdump] / tcpdump.c
index e62babf730fae89a360f50e9612713656c827bf7..1e3d906d0a1210c070d6a39eab4cb0fab379f3f1 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -98,6 +98,7 @@ extern int SIZE_BUF;
 netdissect_options Gndo;
 netdissect_options *gndo = &Gndo;
 
+static int Dflag;                      /* list available devices and exit */
 static int dflag;                      /* print filter code */
 static int Lflag;                      /* list available data link types and exit */
 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
@@ -340,12 +341,23 @@ static const struct ndo_printer ndo_printers[] = {
 #ifdef DLT_NETANALYZER_TRANSPARENT
        { netanalyzer_transparent_if_print, DLT_NETANALYZER_TRANSPARENT },
 #endif
-#ifdef DLT_NFLOG
+#if defined(DLT_NFLOG) && defined(HAVE_PCAP_NFLOG_H)
        { nflog_if_print,       DLT_NFLOG},
 #endif
        { NULL,                 0 },
 };
 
+static const struct tok status_flags[] = {
+#ifdef PCAP_IF_UP
+       { PCAP_IF_UP,       "Up"       },
+#endif
+#ifdef PCAP_IF_RUNNING
+       { PCAP_IF_RUNNING,  "Running"  },
+#endif
+       { PCAP_IF_LOOPBACK, "Loopback" },
+       { 0, NULL }
+};
+
 if_printer
 lookup_printer(int type)
 {
@@ -483,6 +495,31 @@ show_dlts_and_exit(const char *device, pcap_t *pd)
        exit(0);
 }
 
+#ifdef HAVE_PCAP_FINDALLDEVS
+static void
+show_devices_and_exit (void)
+{
+       pcap_if_t *devpointer;
+       char ebuf[PCAP_ERRBUF_SIZE];
+       int i;
+
+       if (pcap_findalldevs(&devpointer, ebuf) < 0)
+               error("%s", ebuf);
+       else {
+               for (i = 0; devpointer != NULL; i++) {
+                       printf("%d.%s", i+1, devpointer->name);
+                       if (devpointer->description != NULL)
+                               printf(" (%s)", devpointer->description);
+                       if (devpointer->flags != 0)
+                               printf(" [%s]", bittok2str(status_flags, "none", devpointer->flags));
+                       printf("\n");
+                       devpointer = devpointer->next;
+               }
+       }
+       exit(0);
+}
+#endif /* HAVE_PCAP_FINDALLDEVS */
+
 /*
  * Set up flags that might or might not be supported depending on the
  * version of libpcap we're using.
@@ -792,21 +829,9 @@ main(int argc, char **argv)
                        ++dflag;
                        break;
 
-#ifdef HAVE_PCAP_FINDALLDEVS
                case 'D':
-                       if (pcap_findalldevs(&devpointer, ebuf) < 0)
-                               error("%s", ebuf);
-                       else {
-                               for (i = 0; devpointer != 0; i++) {
-                                       printf("%d.%s", i+1, devpointer->name);
-                                       if (devpointer->description != NULL)
-                                               printf(" (%s)", devpointer->description);
-                                       printf("\n");
-                                       devpointer = devpointer->next;
-                               }
-                       }
-                       return 0;
-#endif /* HAVE_PCAP_FINDALLDEVS */
+                       Dflag++;
+                       break;
 
                case 'L':
                        Lflag++;
@@ -1118,22 +1143,11 @@ main(int argc, char **argv)
                        break;
 #endif
                case 'z':
-                       if (optarg) {
-                               zflag = strdup(optarg);
-                       } else {
-                               usage();
-                               /* NOTREACHED */
-                       }
+                       zflag = strdup(optarg);
                        break;
 
                case 'Z':
-                       if (optarg) {
-                               username = strdup(optarg);
-                       }
-                       else {
-                               usage();
-                               /* NOTREACHED */
-                       }
+                       username = strdup(optarg);
                        break;
 
                default:
@@ -1141,6 +1155,11 @@ main(int argc, char **argv)
                        /* NOTREACHED */
                }
 
+#ifdef HAVE_PCAP_FINDALLDEVS
+       if (Dflag)
+               show_devices_and_exit();
+#endif
+
        switch (tflag) {
 
        case 0: /* Default */
@@ -1847,6 +1866,13 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                        dump_info->CurrentFileName = (char *)malloc(PATH_MAX + 1);
                        if (dump_info->CurrentFileName == NULL)
                                error("dump_packet_and_trunc: malloc");
+                       /*
+                        * Gflag was set otherwise we wouldn't be here. Reset the count
+                        * so multiple files would end with 1,2,3 in the filename.
+                        * The counting is handled with the -C flow after this.
+                        */
+                       Cflag_count = 0;
+
                        /*
                         * This is always the first file in the Cflag
                         * rotation: e.g. 0
@@ -2046,11 +2072,11 @@ print_packet(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
         * version number of the Packet.dll code, to supply the
         * "Wpcap_version" information on Windows.
         */
-       char WDversion[]="current-cvs.tcpdump.org";
+       char WDversion[]="current-git.tcpdump.org";
 #if !defined(HAVE_GENERATED_VERSION)
-       char version[]="current-cvs.tcpdump.org";
+       char version[]="current-git.tcpdump.org";
 #endif
-       char pcap_version[]="current-cvs.tcpdump.org";
+       char pcap_version[]="current-git.tcpdump.org";
        char Wpcap_version[]="3.1";
 #endif