Skip to content

Commit

Permalink
pcap_create() should accept UNICODE device names as well as ASCII ones
Browse files Browse the repository at this point in the history
on Windows.
  • Loading branch information
gianluca committed May 21, 2008
1 parent 1f93b0f commit c975220
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions pcap-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#ifndef lint
static const char rcsid[] _U_ =
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.41 2008-04-25 20:03:34 gianluca Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.42 2008-05-21 22:15:25 gianluca Exp $ (LBL)";
#endif

#include <pcap-int.h>
Expand Down Expand Up @@ -698,7 +698,38 @@ pcap_create(const char *device, char *ebuf)
{
pcap_t *p;

p = pcap_create_common(device, ebuf);
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)
{
snprintf(ebuf, PCAP_ERRBUF_SIZE, "Malloc failed");
return NULL;
}

snprintf(deviceAscii, length + 1, "%ws", (wchar_t*)device);
p = pcap_create_common(deviceAscii, ebuf);
free(deviceAscii);
}
else
{
p = pcap_create_common(device, ebuf);
}

if (p == NULL)
return (NULL);

Expand Down

0 comments on commit c975220

Please sign in to comment.