Re: [PATCH] iphlpapi: Implement if_nametoindex.
On Wed, May 24, 2017 at 7:39 AM, Stefan Dösinger <stefan(a)codeweavers.com> wrote:
... diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 796950e0f9..4cceb65621 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -36,6 +36,9 @@ #ifdef HAVE_RESOLV_H # include <resolv.h> #endif +#ifdef HAVE_NET_IF_H +# include <net/if.h> +#endif
#define NONAMELESSUNION #define NONAMELESSSTRUCT @@ -3208,3 +3211,12 @@ DWORD WINAPI ConvertInterfaceNameToLuidW(const WCHAR *name, NET_LUID *luid) luid->Info.IfType = row.dwType; return NO_ERROR; } + +/****************************************************************** + * if_nametoindex (IPHLPAPI.@) + */ +IF_INDEX WINAPI IPHLP_if_nametoindex(const char *name) +{ + TRACE("(%s)\n", name); + return if_nametoindex(name); +}
Hi, this seems to be the ASCII version of GetAdapterIndex, can't you call getInterfaceIndexByName and avoid the new #include? Best wishes, Bruno
Am 24.05.2017 um 13:37 schrieb Bruno Jesus <00cpxxx(a)gmail.com>:
Hi, this seems to be the ASCII version of GetAdapterIndex, can't you call getInterfaceIndexByName and avoid the new #include? I’m not sure what you mean by "ASCII version“. getInterfaceIndexByName also accepts a const char * rather than a WCHAR *. It seems to be the non-Microsoft version of getInterfaceIndexByName though.
getInterfaceIndexByName is just a wrapper around if_nametoindex. If I wrap IPHLP_if_nametoindex to getInterfaceByName I’d simply undo all the work getInterfaceByName does (or well, the part where it returns ERROR_INVALID_DATA instead of 0. I’m not sure if avoiding the #include is worth that. I’ll send a version that does that in a bit, you can then sign off on the one you prefer :-)
On Wed, 2017-05-24 at 14:17 +0200, Stefan Dösinger wrote:
Am 24.05.2017 um 13:37 schrieb Bruno Jesus <00cpxxx(a)gmail.com>:
Hi, this seems to be the ASCII version of GetAdapterIndex, can't you call getInterfaceIndexByName and avoid the new #include?
I’m not sure what you mean by "ASCII version“. getInterfaceIndexByName also accepts a const char * rather than a WCHAR *. It seems to be the non-Microsoft version of getInterfaceIndexByName though.
getInterfaceIndexByName is just a wrapper around if_nametoindex. If I wrap IPHLP_if_nametoindex to getInterfaceByName I’d simply undo all the work getInterfaceByName does (or well, the part where it returns ERROR_INVALID_DATA instead of 0. I’m not sure if avoiding the #include is worth that. I’ll send a version that does that in a bit, you can then sign off on the one you prefer :-)
Why not call ConvertInterfaceNameToLuidA and then ConvertInterfaceLuidToIndex?
Am 24.05.2017 um 14:26 schrieb Hans Leidekker <hans(a)codeweavers.com>:
Why not call ConvertInterfaceNameToLuidA and then ConvertInterfaceLuidToIndex? Maybe I am missing something, but this looks like an even more elaborate way to implement a function that has a 1:1 match in the native library. ConvertInterfaceNameToLuidA calls getInterfaceIndexByName to do its work.
Unless I am missing something and we’re doing an elaborate interface number reordering that I can’t find in the code…
On Wed, May 24, 2017 at 9:35 AM, Stefan Dösinger <stefan(a)codeweavers.com> wrote:
Am 24.05.2017 um 14:26 schrieb Hans Leidekker <hans(a)codeweavers.com>:
Why not call ConvertInterfaceNameToLuidA and then ConvertInterfaceLuidToIndex? Maybe I am missing something, but this looks like an even more elaborate way to implement a function that has a 1:1 match in the native library. ConvertInterfaceNameToLuidA calls getInterfaceIndexByName to do its work.
Unless I am missing something and we’re doing an elaborate interface number reordering that I can’t find in the code…
I believe iphlpapi is split in different source files to try separating the OS (ifenum.c/ifstats.c) code to the unix->windows conversion code (iphlpapi_main.c). That was the idea to reuse the other function from ifenum, if that is not what the file division was meant to mean then your patch is certainly fine ;-)
Am 24.05.2017 um 14:26 schrieb Hans Leidekker <hans(a)codeweavers.com>:
Why not call ConvertInterfaceNameToLuidA and then ConvertInterfaceLuidToIndex? Hmm, I think I see what you mean now. WGC passes a string like "{00000001-0000-0000-0000-000000000000}“ to if_nametoindex, which I suspect is not what the POSIX function with the same name expects. I think this warrants some tests.
On Wed, May 24, 2017 at 9:17 AM, Stefan Dösinger <stefan(a)codeweavers.com> wrote:
I’m not sure what you mean by "ASCII version“. getInterfaceIndexByName also accepts a const char * rather than a WCHAR *.
I meant a "char* version of GetAdapterIndex", which receives a WCHAR*.
Am 24.05.2017 um 14:36 schrieb Bruno Jesus <00cpxxx(a)gmail.com>:
On Wed, May 24, 2017 at 9:17 AM, Stefan Dösinger <stefan(a)codeweavers.com> wrote:
I’m not sure what you mean by "ASCII version“. getInterfaceIndexByName also accepts a const char * rather than a WCHAR *.
I meant a "char* version of GetAdapterIndex", which receives a WCHAR*. Calling GetAdapterIndex seems kinda wasteful as well, we’d have to convert to WCHAR, then GetAdapterIndex converts back to char and calls getInterfaceIndexByName, which calls if_nametoindex, which is where we started.
On Wed, May 24, 2017 at 9:43 AM, Stefan Dösinger <stefan(a)codeweavers.com> wrote:
On Wed, May 24, 2017 at 9:17 AM, Stefan Dösinger <stefan(a)codeweavers.com> wrote:
I’m not sure what you mean by "ASCII version“. getInterfaceIndexByName also accepts a const char * rather than a WCHAR *.
I meant a "char* version of GetAdapterIndex", which receives a WCHAR*.
Calling GetAdapterIndex seems kinda wasteful as well, we’d have to convert to WCHAR, then GetAdapterIndex converts back to char and calls getInterfaceIndexByName, which calls if_nametoindex, which is where we started.
No, that was not what I meant. I just said that if_nametoindex is char*, while GetAdapterIndex is a WCHAR*, I didn't say you have to use GetAdapterIndex.
participants (3)
-
Bruno Jesus -
Hans Leidekker -
Stefan Dösinger