X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/0d1a405289e19c154d3b28d5c9e244fd13492810..4a2fb51da7ada0cecf94a5a94c7146bc36dd72b0:/tcpdump.c diff --git a/tcpdump.c b/tcpdump.c index 52dbf7e5..bde74864 100644 --- 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 */