#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 */
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.
#endif
}
-#ifndef _WIN32
if (RFileName == NULL) {
/*
* Live capture (if -V was specified, we set RFileName
}
(void)fflush(stderr);
}
-#endif /* _WIN32 */
#ifdef HAVE_CAPSICUM
cansandbox = (ndo->ndo_nflag && VFileName == NULL && zflag == NULL);