From c975220bd182f6b6eaca26f2675d3a18bae17fcd Mon Sep 17 00:00:00 2001 From: gianluca Date: Wed, 21 May 2008 22:15:25 +0000 Subject: [PATCH] pcap_create() should accept UNICODE device names as well as ASCII ones on Windows. --- pcap-win32.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/pcap-win32.c b/pcap-win32.c index afe6d95..8eb26d9 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -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 @@ -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);