]> The Tcpdump Group git mirrors - tcpdump/blobdiff - tcpdump.c
Fix a warning
[tcpdump] / tcpdump.c
index 52dbf7e53c568e593e75df417f8444a9ed1a3901..bde74864d9ecd7893cbba61063b73445a566d3d4 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -189,6 +189,9 @@ static void print_version(void);
 static void print_usage(void);
 static void show_tstamp_types_and_exit(const char *device) __attribute__((noreturn));
 static void show_dlts_and_exit(const char *device) __attribute__((noreturn));
+#ifdef HAVE_PCAP_FINDALLDEVS
+static void show_devices_and_exit (void) __attribute__((noreturn));
+#endif
 
 static void print_packet(u_char *, const struct pcap_pkthdr *, const u_char *);
 static void dump_packet_and_trunc(u_char *, const struct pcap_pkthdr *, const u_char *);
@@ -828,7 +831,7 @@ copy_argv(register char **argv)
        char *src, *dst;
 
        p = argv;
-       if (*p == 0)
+       if (*p == NULL)
                return 0;
 
        while (*p)
@@ -958,8 +961,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 +1082,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 */