[PATCH] packet: create packet.dll and Implement PacketGetAdapterNames(try 6)
Sebastian Lackner
sebastian at fds-team.de
Thu Feb 25 09:48:54 CST 2016
On 25.02.2016 15:55, Jianqiu Zhang wrote:
>
> 0001-packet-create-packet.dll-and-Implement-PacketGetAdapte.txt
>
>
> From 9853273e566d9ae34bbfef459a730e3701d54d22 Mon Sep 17 00:00:00 2001
> From: Jianqiu Zhang <zhangjianqiu_133 at 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 at yeah.net>
> ---
> configure.ac | 7 +++--
> dlls/packet/Makefile.in | 5 +++
> dlls/packet/packet.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++
> dlls/packet/packet.spec | 32 +++++++++++++++++++
> dlls/wpcap/Makefile.in | 1 +
> 5 files changed, 124 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..0e9ff97
> --- /dev/null
> +++ b/dlls/packet/packet.c
> @@ -0,0 +1,81 @@
> +#include "config.h"
> +
> +#include "windows.h"
> +#include "wine/debug.h"
> +
> +#include "pcap.h"
As pointed out on IRC yesterday, the system pcap.h header file declares functions
with the wrong calling convention. You would have to add a separate wine header file,
or directly use the linux pcap library (without going through wpcap).
> +
> +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;
> + char empty_str[] = "";
> +
> + TRACE("(%p, %p)\n", name_list, size);
> +
> + ret = pcap_findalldevs(&alldevs, errbuf);
> +
> + if (ret)
> + {
> + pcap_freealldevs(alldevs);
> + return FALSE;
> + }
> + ptr = alldevs;
> + min_name_size = min_desc_size = min_size = 0;
> + while (ptr)
> + {
> + /* Work around bug in libpcap ptr->description == NULL when no description got */
> + if (ptr->description == NULL)
> + {
> + ptr->description = empty_str;
> + }
> +
> + 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, ""))
> + {
> + ptr->description = NULL;
It is not really clear to me why you change ->description to an empty string,
just to change it back here. If its only for the size computation, why not
just handle this case separately?
> + }
> + ptr = ptr->next;
> + }
> + SetLastError(ERROR_INSUFFICIENT_BUFFER);
> + pcap_freealldevs(alldevs);
> + *size = min_size;
As pointed out in one of the previous mails, the official packet.dll doesn't
seem to do that (at least the versions I found).
> + 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, ""))
> + {
> + 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
>
>
>
More information about the wine-devel
mailing list