Am 23.02.2016 um 09:44 schrieb Jianqiu Zhang:
According to advice frome André Hentschel, implement packet.dll using the method of calling wine wpcap function, rewrite PacketGetAdapterNames.
From 691679b504530c38c400813bacbc416c28028655 Mon Sep 17 00:00:00 2001 From: Jianqiu Zhang zhangjianqiu_133@yeah.net Date: Sun, 14 Feb 2016 17:27:37 +0800 Subject: [PATCH] packet: create packet.dll and Implement PacketGetAdapterNames
Signed-off-by: Jianqiu Zhang zhangjianqiu_133@yeah.net
configure.ac | 7 ++-- dlls/packet/Makefile.in | 5 +++ dlls/packet/packet.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ dlls/packet/packet.spec | 32 +++++++++++++++++++ dlls/wpcap/Makefile.in | 1 + 5 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 dlls/packet/Makefile.in create mode 100644 dlls/packet/packet.c create mode 100644 dlls/packet/packet.spec
diff --git a/configure.ac b/configure.ac index c9445e7..b61a5c2 100644 --- a/configure.ac +++ b/configure.ac @@ -1185,8 +1185,10 @@ then AC_CHECK_LIB(pcap,pcap_create,[AC_SUBST(PCAP_LIBS,["-lpcap"])]) fi WINE_NOTICE_WITH(pcap,[test "x$ac_cv_lib_pcap_pcap_create" != xyes],
[pcap ${notice_platform}development files not found, wpcap won't be supported.])
[pcap ${notice_platform}development files not found, wpcap and packet won't be supported.])
test "x$ac_cv_lib_pcap_pcap_create" != xyes && enable_wpcap=${enable_wpcap:-no} +test "x$ac_cv_lib_pcap_pcap_create" != xyes && enable_packet=${enable_packet:-no}
dnl **** Check for libxml2 ****
@@ -3180,6 +3182,7 @@ WINE_CONFIG_DLL(opengl32,,[implib]) WINE_CONFIG_TEST(dlls/opengl32/tests) WINE_CONFIG_DLL(packager,,[clean]) WINE_CONFIG_TEST(dlls/packager/tests) +WINE_CONFIG_DLL(packet) WINE_CONFIG_DLL(pdh,,[implib]) WINE_CONFIG_TEST(dlls/pdh/tests) WINE_CONFIG_DLL(photometadatahandler) @@ -3388,7 +3391,7 @@ WINE_CONFIG_TEST(dlls/wmp/tests) WINE_CONFIG_DLL(wmvcore) WINE_CONFIG_DLL(wnaspi32,,[implib]) WINE_CONFIG_DLL(wow32,enable_win16,[implib]) -WINE_CONFIG_DLL(wpcap) +WINE_CONFIG_DLL(wpcap,,[implib]) WINE_CONFIG_DLL(ws2_32,,[implib]) WINE_CONFIG_TEST(dlls/ws2_32/tests) WINE_CONFIG_DLL(wshom.ocx,,[clean]) diff --git a/dlls/packet/Makefile.in b/dlls/packet/Makefile.in new file mode 100644 index 0000000..9caced8 --- /dev/null +++ b/dlls/packet/Makefile.in @@ -0,0 +1,5 @@ +MODULE = packet.dll +IMPORTS = wpcap
+C_SRCS = \
- packet.c
diff --git a/dlls/packet/packet.c b/dlls/packet/packet.c new file mode 100644 index 0000000..2b002ec --- /dev/null +++ b/dlls/packet/packet.c @@ -0,0 +1,85 @@ +#include "config.h"
+#include "windows.h" +#include "wine/debug.h"
+#include "pcap.h"
+WINE_DEFAULT_DEBUG_CHANNEL(packet);
+BOOLEAN CDECL PacketGetAdapterNames(char *name_list, ULONG *size) +{
- pcap_if_t *alldevs, *ptr;
- char errbuf[PCAP_ERRBUF_SIZE];
- int min_desc_size, min_name_size, min_size, desc_offset, name_offset;
- DWORD ret;
- TRACE("(%p, %p)\n", name_list, size);
- ret = pcap_findalldevs(&alldevs, errbuf);
- TRACE("ret = %d, alldevs = %p\n", ret, alldevs);
Only useful for debugging
- if(ret)
- {
pcap_freealldevs(alldevs);
return FALSE;
- }
- ptr = alldevs;
- min_name_size = min_desc_size = min_size = 0;
- while(ptr)
some blank lines would be great above, also we normally use a space between C keywords (if, while, ...) and the parenthesis
- {
/* Work around bug in libpcap ptr->description == NULL when no description got */
if(ptr->description == NULL)
{
ptr->description = (char *)HeapAlloc(GetProcessHeap(), 0, sizeof(char));
*(ptr->description) = '\0';
Can't we simply use a static const "" here? That also would avoid the hack later to free the heap space
}
min_name_size += strlen(ptr->name) + 1;
min_desc_size += strlen(ptr->description) + 1;
ptr = ptr->next;
- }
- min_size = min_name_size + min_desc_size + 2;
- if(!name_list || *size < min_size)
- {
ptr = alldevs;
while(ptr)
{
if(!strcmp(ptr->description, ""))
{
HeapFree(GetProcessHeap(), 0, ptr->description);
ptr->description = NULL;
}
ptr = ptr->next;
}
SetLastError(ERROR_INSUFFICIENT_BUFFER);
pcap_freealldevs(alldevs);
*size = min_size;
return FALSE;
- }
- ptr = alldevs;
- desc_offset = name_offset = 0;
- while(ptr)
- {
strcpy(name_list + name_offset, ptr->name);
strcpy(name_list + min_name_size + desc_offset + 1, ptr->description);
name_offset += strlen(ptr->name) + 1;
desc_offset += strlen(ptr->description) + 1;
/* Work around bug in libpcap ptr->description == NULL when no description got */
if(!strcmp(ptr->description, ""))
{
HeapFree(GetProcessHeap(), 0, ptr->description);
ptr->description = NULL;
}
ptr = ptr->next;
- }
- name_list[min_name_size] = '\0';
- name_list[min_size - 1] = '\0';
- pcap_freealldevs(alldevs);
- return TRUE;
+} diff --git a/dlls/packet/packet.spec b/dlls/packet/packet.spec new file mode 100644 index 0000000..32b9bc0 --- /dev/null +++ b/dlls/packet/packet.spec @@ -0,0 +1,32 @@ +@ stub PacketAllocatePacket +@ stub PacketCloseAdapter +@ stub PacketFreePacket +@ cdecl PacketGetAdapterNames(ptr ptr) +@ stub PacketGetAirPcapHandle +@ stub PacketGetDriverVersion +@ stub PacketGetNetInfoEx +@ stub PacketGetNetType +@ stub PacketGetReadEvent +@ stub PacketGetStats +@ stub PacketGetStatsEx +@ stub PacketGetVersion +@ stub PacketInitPacket +@ stub PacketIsDumpEnded +@ stub PacketLibraryVersion +@ stub PacketOpenAdapter +@ stub PacketReceivePacket +@ stub PacketRequest +@ stub PacketSendPacket +@ stub PacketSendPackets +@ stub PacketSetBpf +@ stub PacketSetBuff +@ stub PacketSetDumpLimits +@ stub PacketSetDumpName +@ stub PacketSetHwFilter +@ stub PacketSetLoopbackBehavior +@ stub PacketSetMinToCopy +@ stub PacketSetMode +@ stub PacketSetNumWrites +@ stub PacketSetReadTimeout +@ stub PacketSetSnapLen +@ stub PacketStopDriver diff --git a/dlls/wpcap/Makefile.in b/dlls/wpcap/Makefile.in index 91b4a95..e9794cf 100644 --- a/dlls/wpcap/Makefile.in +++ b/dlls/wpcap/Makefile.in @@ -1,6 +1,7 @@ MODULE = wpcap.dll DELAYIMPORTS = ws2_32 EXTRALIBS = $(PCAP_LIBS) +IMPORTLIB = wpcap
C_SRCS = \ wpcap.c -- 2.7.1
Hi Andre
some blank lines would be great above, also we normally use a space between C keywords (if, while, ...) and the parenthesis
- {
/* Work around bug in libpcap ptr->description == NULL when no description got */
if(ptr->description == NULL)
{
ptr->description = (char *)HeapAlloc(GetProcessHeap(), 0, sizeof(char));
*(ptr->description) = '\0';
Can't we simply use a static const "" here? That also would avoid the hack later to free the heap space
Yes, I can use char empty_str[] = '" to avoid the memory alloc , but I also need to do the ptr->description = NULL when clean up , Or it will crash when calling pcap_freealldevs, Is there any way not to make ptr->description = NULL and avoid the crash? Thanks
}
min_name_size += strlen(ptr->name) + 1;
min_desc_size += strlen(ptr->description) + 1;
ptr = ptr->next;
- }
- min_size = min_name_size + min_desc_size + 2;
- if(!name_list || *size < min_size)
- {
ptr = alldevs;
while(ptr)
{
if(!strcmp(ptr->description, ""))
{
HeapFree(GetProcessHeap(), 0, ptr->description);
ptr->description = NULL;
}
ptr = ptr->next;
}
SetLastError(ERROR_INSUFFICIENT_BUFFER);
pcap_freealldevs(alldevs);
*size = min_size;
return FALSE;
- }
- ptr = alldevs;
- desc_offset = name_offset = 0;
- while(ptr)
- {
strcpy(name_list + name_offset, ptr->name);
strcpy(name_list + min_name_size + desc_offset + 1, ptr->description);
name_offset += strlen(ptr->name) + 1;
desc_offset += strlen(ptr->description) + 1;
/* Work around bug in libpcap ptr->description == NULL when no description got */
if(!strcmp(ptr->description, ""))
{
HeapFree(GetProcessHeap(), 0, ptr->description);
ptr->description = NULL;
}
ptr = ptr->next;
- }
- name_list[min_name_size] = '\0';
- name_list[min_size - 1] = '\0';
- pcap_freealldevs(alldevs);
- return TRUE;
+} diff --git a/dlls/packet/packet.spec b/dlls/packet/packet.spec new file mode 100644 index 0000000..32b9bc0 --- /dev/null +++ b/dlls/packet/packet.spec @@ -0,0 +1,32 @@ +@ stub PacketAllocatePacket +@ stub PacketCloseAdapter +@ stub PacketFreePacket +@ cdecl PacketGetAdapterNames(ptr ptr) +@ stub PacketGetAirPcapHandle +@ stub PacketGetDriverVersion +@ stub PacketGetNetInfoEx +@ stub PacketGetNetType +@ stub PacketGetReadEvent +@ stub PacketGetStats +@ stub PacketGetStatsEx +@ stub PacketGetVersion +@ stub PacketInitPacket +@ stub PacketIsDumpEnded +@ stub PacketLibraryVersion +@ stub PacketOpenAdapter +@ stub PacketReceivePacket +@ stub PacketRequest +@ stub PacketSendPacket +@ stub PacketSendPackets +@ stub PacketSetBpf +@ stub PacketSetBuff +@ stub PacketSetDumpLimits +@ stub PacketSetDumpName +@ stub PacketSetHwFilter +@ stub PacketSetLoopbackBehavior +@ stub PacketSetMinToCopy +@ stub PacketSetMode +@ stub PacketSetNumWrites +@ stub PacketSetReadTimeout +@ stub PacketSetSnapLen +@ stub PacketStopDriver diff --git a/dlls/wpcap/Makefile.in b/dlls/wpcap/Makefile.in index 91b4a95..e9794cf 100644 --- a/dlls/wpcap/Makefile.in +++ b/dlls/wpcap/Makefile.in @@ -1,6 +1,7 @@ MODULE = wpcap.dll DELAYIMPORTS = ws2_32 EXTRALIBS = $(PCAP_LIBS) +IMPORTLIB = wpcap
C_SRCS = \ wpcap.c -- 2.7.1