]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Add a summary comment in all other printers
[tcpdump] / tcpdump.c
index 97e2aa55ca9f453a23725ba5bceb1a11d848ef9e..d5bf09bdef87bcd5d8bcb47c8d1aff5144b6d052 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -958,8 +958,17 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf)
 
 #ifdef HAVE_PCAP_CREATE
        pc = pcap_create(device, ebuf);
-       if (pc == NULL)
+       if (pc == NULL) {
+               /*
+                * If this failed with "No such device", that means
+                * the interface doesn't exist; return NULL, so that
+                * the caller can see whether the device name is
+                * actually an interface index.
+                */
+               if (strstr(ebuf, "No such device") != NULL)
+                       return (NULL);
                error("%s", ebuf);
+       }
 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
        if (Jflag)
                show_tstamp_types_and_exit(device);
@@ -1070,9 +1079,18 @@ open_interface(const char *device, netdissect_options *ndo, char *ebuf)
 #else /* HAVE_PCAP_CREATE */
        *ebuf = '\0';
        pc = pcap_open_live(device, ndo->ndo_snaplen, !pflag, 1000, ebuf);
-       if (pc == NULL)
+       if (pc == NULL) {
+               /*
+                * If this failed with "No such device", that means
+                * the interface doesn't exist; return NULL, so that
+                * the caller can see whether the device name is
+                * actually an interface index.
+                */
+               if (strstr(ebuf, "No such device") != NULL)
+                       return (NULL);
                error("%s", ebuf);
-       else if (*ebuf)
+       }
+       if (*ebuf)
                warning("%s", ebuf);
 #endif /* HAVE_PCAP_CREATE */
 
@@ -1650,22 +1668,6 @@ main(int argc, char **argv)
                        if (device == NULL)
                                error("%s", ebuf);
                }
-#ifdef _WIN32
-               /*
-                * Print a message to the standard error on Windows.
-                * XXX - why do it here, with a different message?
-                */
-               if(strlen(device) == 1) /* we assume that an ASCII string is always longer than 1 char */
-               {                                               /* a Unicode string has a \0 as second byte (so strlen() is 1) */
-                       fprintf(stderr, "%s: listening on %ws\n", program_name, device);
-               }
-               else
-               {
-                       fprintf(stderr, "%s: listening on %s\n", program_name, device);
-               }
-
-               fflush(stderr);
-#endif /* _WIN32 */
 
                /*
                 * Try to open the interface with the specified name.
@@ -1956,7 +1958,6 @@ main(int argc, char **argv)
 #endif
        }
 
-#ifndef _WIN32
        if (RFileName == NULL) {
                /*
                 * Live capture (if -V was specified, we set RFileName
@@ -1981,7 +1982,6 @@ main(int argc, char **argv)
                }
                (void)fflush(stderr);
        }
-#endif /* _WIN32 */
 
 #ifdef HAVE_CAPSICUM
        cansandbox = (ndo->ndo_nflag && VFileName == NULL && zflag == NULL);