Instead, have pcap_create() do so.
Also have pcap_create() on Windows handle converting a little-endian
UCS-2/UTF-16 string to ASCII.
#endif /* HAVE_ZEROCOPY_BPF */
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_bpf));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_bpf));
if (p == NULL)
return (NULL);
#endif
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
#ifdef DL_HP_RAWDLS
struct pcap_dlpi *pd;
#endif
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_dlpi));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_dlpi));
if (p == NULL)
return (NULL);
struct pcap_stat stat;
};
-pcap_t *pcap_create_interface (const char *device, char *ebuf)
+pcap_t *pcap_create_interface (char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_dos));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_dos));
if (p == NULL)
return (NULL);
* "pcap_create_common()" allocates and fills in a pcap_t, for use
* by pcap_create routines.
*/
-pcap_t *pcap_create_interface(const char *, char *);
-pcap_t *pcap_create_common(const char *, char *, size_t);
+pcap_t *pcap_create_interface(char *);
+pcap_t *pcap_create_common(char *, size_t);
int pcap_do_addexit(pcap_t *);
void pcap_add_to_pcaps_to_close(pcap_t *);
void pcap_remove_from_pcaps_to_close(pcap_t *);
}
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_dlpi));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_dlpi));
if (p == NULL)
return (NULL);
#endif /* SO_ATTACH_FILTER */
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *handle;
- handle = pcap_create_common(device, ebuf, sizeof (struct pcap_linux));
+ handle = pcap_create_common(ebuf, sizeof (struct pcap_linux));
if (handle == NULL)
return NULL;
}
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_nit));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_nit));
if (p == NULL)
return (NULL);
static char nosup[] = "live packet capture not supported on this system";
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
(void)strlcpy(ebuf, nosup, PCAP_ERRBUF_SIZE);
return (NULL);
}
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_pf));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_pf));
if (p == NULL)
return (NULL);
return 0;
}
-pcap_t *pcap_create_interface(const char *device, char *ebuf) {
+pcap_t *pcap_create_interface(char *ebuf) {
pcap_t *p;
- p = pcap_create_common(device, ebuf, 0);
+ p = pcap_create_common(ebuf, 0);
if (p == NULL)
return (NULL);
}
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_snit));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_snit));
if (p == NULL)
return (NULL);
}
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_snoop));
+ p = pcap_create_common(ebuf, sizeof (struct pcap_snoop));
if (p == NULL)
return (NULL);
}
pcap_t *
-pcap_create_interface(const char *device, char *ebuf)
+pcap_create_interface(char *ebuf)
{
pcap_t *p;
- if (strlen(device) == 1)
- {
- /*
- * It's probably a unicode string
- * Convert to ascii and pass it to pcap_create_common
- *
- * This wonderful hack is needed because pcap_lookupdev still returns
- * unicode strings, and it's used by windump when no device is specified
- * in the command line
- */
- size_t length;
- char* deviceAscii;
-
- length = wcslen((wchar_t*)device);
-
- deviceAscii = (char*)malloc(length + 1);
-
- if (deviceAscii == NULL)
- {
- pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "Malloc failed");
- return (NULL);
- }
-
- pcap_snprintf(deviceAscii, length + 1, "%ws", (wchar_t*)device);
- p = pcap_create_common(deviceAscii, ebuf, sizeof (struct pcap_win));
- free(deviceAscii);
- }
- else
- {
- p = pcap_create_common(device, ebuf, sizeof (struct pcap_win));
- }
-
+ p = pcap_create_common(ebuf, sizeof (struct pcap_win));
if (p == NULL)
return (NULL);
size_t i;
int is_theirs;
pcap_t *p;
+ char *device_str;
/*
* A null device name is equivalent to the "any" device -
* the null pointer.
*/
if (device == NULL)
- device = "any";
+ device_str = strdup("any");
+ else {
+#ifdef _WIN32
+ /*
+ * If the string appears to be little-endian UCS-2/UTF-16,
+ * convert it to ASCII.
+ *
+ * XXX - to UTF-8 instead? Or report an error if any
+ * character isn't ASCII?
+ */
+ if (device[0] != '\0' && device[1] == '\0') {
+ size_t length;
+ char *device_ascii;
+
+ length = wcslen((wchar_t *)device);
+ device_str = (char *)malloc(length + 1);
+ if (device_str == NULL) {
+ pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
+ "malloc: %s", pcap_strerror(errno));
+ return (NULL);
+ }
+
+ pcap_snprintf(device, length + 1, "%ws",
+ (wchar_t *)device);
+ } else
+#endif
+ device_str = strdup(device);
+ }
+ if (device_str == NULL) {
+ pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
+ "malloc: %s", pcap_strerror(errno));
+ return (NULL);
+ }
/*
* Try each of the non-local-network-interface capture
*/
for (i = 0; capture_source_types[i].create_op != NULL; i++) {
is_theirs = 0;
- p = capture_source_types[i].create_op(device, errbuf, &is_theirs);
+ p = capture_source_types[i].create_op(device_str, errbuf,
+ &is_theirs);
if (is_theirs) {
/*
* The device name refers to a device of the
* should return that to report the failure
* to create.
*/
+ if (p == NULL) {
+ /*
+ * We assume the caller filled in errbuf.
+ */
+ free(device_str);
+ return (NULL);
+ }
+ p->opt.device = device_str;
return (p);
}
}
/*
* OK, try it as a regular network interface.
*/
- return (pcap_create_interface(device, errbuf));
+ p = pcap_create_interface(errbuf);
+ if (p == NULL) {
+ /*
+ * We assume the caller filled in errbuf.
+ */
+ free(device_str);
+ return (NULL);
+ }
+ p->opt.device = device_str;
+ return (p);
}
#endif
}
pcap_t *
-pcap_create_common(const char *device, char *ebuf, size_t size)
+pcap_create_common(char *ebuf, size_t size)
{
pcap_t *p;
if (p == NULL)
return (NULL);
- p->opt.device = strdup(device);
- if (p->opt.device == NULL) {
- pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
- pcap_strerror(errno));
- free(p);
- return (NULL);
- }
-
/*
* Default to "can't set rfmon mode"; if it's supported by
* a platform, the create routine that called us can set
return (NULL);
p->opt.tstamp_precision = PCAP_TSTAMP_PRECISION_MICRO;
- p->opt.device = strdup("(savefile)");
- if (p->opt.device == NULL) {
- pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s",
- pcap_strerror(errno));
- free(p);
- return (NULL);
- }
return (p);
}