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 *);
char *src, *dst;
p = argv;
- if (*p == 0)
+ if (*p == NULL)
return 0;
while (*p)
#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);
#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 */