dect
/
libpcap
Archived
13
0
Fork 0

pcap_create() should accept UNICODE device names as well as ASCII ones

on Windows.
This commit is contained in:
gianluca 2008-05-21 22:15:25 +00:00
parent 1f93b0fda9
commit c975220bd1
1 changed files with 33 additions and 2 deletions

View File

@ -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>
@ -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);