Thanks for sending an updated version of your patch. I have some more comments below.
Nevertheless, before you spent too much time to fix all the issues, I would suggest
to discuss with André first, if packet.dll is acceptable for Wine. One reason why we
might consider adding it is because the original version heavily reads information
from the registry (SYSTEM\\CurrentControlSet), which is not populated by Wine, but
still there might be alternative ways to solve it.
If we really reimplement this DLL, we might also need tests in the long term, otherwise
its difficult to say if everything is implemented correctly.
On 18.02.2016 14:21, Jianqiu Zhang wrote:
>
> 0001-packet-create-packet.dll-and-Implement-GetAdapterNames.txt
>
>
> From 06eb579dba41bc473429d262150677687f1f092a Mon Sep 17 00:00:00 2001
> From: Jianqiu Zhang <zhangjianqiu_133(a)yeah.net>
> Date: Sun, 14 Feb 2016 17:27:37 +0800
> Subject: [PATCH] packet: create packet.dll and Implement GetAdapterNames
>
> Signed-off-by: Jianqiu Zhang <zhangjianqiu_133(a)yeah.net>
> ---
> configure.ac | 7 +++++++
> dlls/packet/Makefile.in | 5 +++++
> dlls/packet/packet.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++
> dlls/packet/packet.spec | 32 ++++++++++++++++++++++++++++
> 4 files changed, 100 insertions(+)
> 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..504d46e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -69,6 +69,8 @@ AC_ARG_WITH(osmesa, AS_HELP_STRING([--without-osmesa],[do not use the OSMesa
> AC_ARG_WITH(oss, AS_HELP_STRING([--without-oss],[do not use the OSS sound support]))
> AC_ARG_WITH(pcap, AS_HELP_STRING([--without-pcap],[do not use the Packet Capture library]),
> [if test "x$withval" = "xno"; then ac_cv_header_pcap_pcap_h=no; fi])
> +AC_ARG_WITH(packet, AS_HELP_STRING([--without-packet],[do not use the Packet DLL]),
> + [if test "x$withval" = "xno"; then ac_cv_header_pcap_pcap_h=no; fi])
You can leave this part out, packet.dll does not require separate dependencies.
> AC_ARG_WITH(png, AS_HELP_STRING([--without-png],[do not use PNG]))
> AC_ARG_WITH(pthread, AS_HELP_STRING([--without-pthread],[do not use the pthread library]),
> [if test "x$withval" = "xno"; then ac_cv_header_pthread_h=no; fi])
> @@ -1186,7 +1188,11 @@ then
> 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.])
> +WINE_NOTICE_WITH(packet,[test "x$ac_cv_lib_pcap_pcap_create" != xyes],
> + [pcap ${notice_platform}development files not found, packet won't be supported.])
A separate WINE_NOTICE_WITH is also not necessary. Instead just modify the existing one, for example:
"""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 ****
>
> @@ -3389,6 +3395,7 @@ WINE_CONFIG_DLL(wmvcore)
> WINE_CONFIG_DLL(wnaspi32,,[implib])
> WINE_CONFIG_DLL(wow32,enable_win16,[implib])
> WINE_CONFIG_DLL(wpcap)
> +WINE_CONFIG_DLL(packet)
These lines are alphabetically sorted, so you would have to insert it at a different position.
Please note that you can also use ./tools/make_makefiles to add this line for you, after you
have added files for a new dll to git.
> 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..cecf07c
> --- /dev/null
> +++ b/dlls/packet/Makefile.in
> @@ -0,0 +1,5 @@
> +MODULE = packet.dll
> +IMPORTS = iphlpapi
> +
> +C_SRCS = \
> + packet.c
> diff --git a/dlls/packet/packet.c b/dlls/packet/packet.c
> new file mode 100644
> index 0000000..1074067
> --- /dev/null
> +++ b/dlls/packet/packet.c
> @@ -0,0 +1,56 @@
> +#include "config.h"
> +
> +#include "windows.h"
> +#include "wine/debug.h"
> +
> +#include "iphlpapi.h"
> +
> +WINE_DEFAULT_DEBUG_CHANNEL(packet);
> +
> +BOOLEAN CDECL PacketGetAdapterNames(char *name_list, ULONG *size)
> +{
> + IP_ADAPTER_INFO *adInfo, *adInfoList = NULL;
> + DWORD errcode;
> + ULONG needsize = 0, minDescLen = 0, minAdNameLen = 0, minTotLen = 0, nameOffset, descOffset;
> +
> + TRACE("name_list %p &size %p size %d\n", name_list, size, *size);
> +
> + errcode = GetAdaptersInfo(adInfoList, &needsize);
> + adInfoList = HeapAlloc(GetProcessHeap(), 0, needsize);
> + if(adInfoList == NULL) return FALSE;
> +
> + errcode = GetAdaptersInfo(adInfoList, &needsize);
> + if(errcode)
> + {
> + HeapFree(GetProcessHeap(), 0, adInfoList);
> + SetLastError(errcode);
> + return FALSE;
> + }
> + for(adInfo = adInfoList; adInfo != NULL; adInfo = adInfo->Next)
> + {
> + minAdNameLen += lstrlenA(adInfo->AdapterName) + 1;
> + minDescLen += lstrlenA(adInfo->Description) + 1;
Usually a direct invocation of strlen() is preferred in the wine source.
> + }
> + minTotLen = minAdNameLen + minDescLen + 2;
> + if(name_list == NULL || *size < minTotLen)
> + {
> + SetLastError(ERROR_INSUFFICIENT_BUFFER);
> + HeapFree(GetProcessHeap(), 0, adInfoList);
> + *size = minTotLen;
When looking through the original implementation of packet.dll, I do not see any location which changes *size.
> + return FALSE;
> + }
> +
> + nameOffset = descOffset = 0;
> + for(adInfo = adInfoList; adInfo != NULL; adInfo = adInfo->Next)
> + {
> + lstrcpyA(name_list + nameOffset, adInfo->AdapterName);
> + lstrcpyA(name_list + minAdNameLen + descOffset + 1, adInfo->Description);
> + nameOffset += lstrlenA(adInfo->AdapterName) + 1;
> + descOffset += lstrlenA(adInfo->Description) + 1;
strcpy / strlen would be preferred here.
> + }
> + name_list[minAdNameLen] = '\0';
> + name_list[minTotLen - 1] = '\0';
> +
> + HeapFree(GetProcessHeap(), 0, adInfoList);
> + 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
> -- 2.7.1
>
>
>