Message ID | 20171012080720.7764-1-simon@rozman.si |
---|---|
State | Accepted |
Headers | show |
Series | [Openvpn-devel] Simplify iphlpapi.dll API calls | expand |
Hi, Note to self: this is v2 of [PATCH 05/13] https://www.mail-archive.com/openvpn-devel@lists.sourceforge .net/msg15589.html On Thu, Oct 12, 2017 at 4:07 AM, Simon Rozman <simon@rozman.si> wrote: > Dynamically locating API function addresses at run-time using > GetProcAddress() was a leftover from the early days of the interactive > service development. It was required before `NTDDI_VERSION` was raised > from Windows XP to Windows Vista. > > After NTDDI_VERSION API level was raised to NTDDI_VISTA, the direct > calling of Vista introduced API functions is possible and much > simpler. > > This patch simplifies the code while in the same time it removes > controversial function type definitions that caused interactive service > not to compile on MSVC. > --- > src/openvpnserv/interactive.c | 123 +----------------------------- > ------------ > 1 file changed, 1 insertion(+), 122 deletions(-) > > diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c > index a060a06..bb8c5f6 100644 > --- a/src/openvpnserv/interactive.c > +++ b/src/openvpnserv/interactive.c > @@ -549,23 +549,6 @@ InterfaceLuid(const char *iface_name, PNET_LUID luid) > LPWSTR wide_name; > int n; > > - typedef NETIO_STATUS WINAPI (*ConvertInterfaceAliasToLuidFn) > (LPCWSTR, PNET_LUID); > - static ConvertInterfaceAliasToLuidFn ConvertInterfaceAliasToLuid = > NULL; > - if (!ConvertInterfaceAliasToLuid) > - { > - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); > - if (iphlpapi == NULL) > - { > - return GetLastError(); > - } > - > - ConvertInterfaceAliasToLuid = (ConvertInterfaceAliasToLuidFn) > GetProcAddress(iphlpapi, "ConvertInterfaceAliasToLuid"); > - if (!ConvertInterfaceAliasToLuid) > - { > - return GetLastError(); > - } > - } > - > n = MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, NULL, 0); > wide_name = malloc(n * sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, wide_name, n); > Not a fault of this patch, but malloc's return value not checked... Let's address that in a separate patch. > @@ -584,24 +567,6 @@ CmpAddress(LPVOID item, LPVOID address) > static DWORD > DeleteAddress(PMIB_UNICASTIPADDRESS_ROW addr_row) > { > - typedef NETIOAPI_API (*DeleteUnicastIpAddressEntryFn) (const > PMIB_UNICASTIPADDRESS_ROW); > - static DeleteUnicastIpAddressEntryFn DeleteUnicastIpAddressEntry = > NULL; > - > - if (!DeleteUnicastIpAddressEntry) > - { > - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); > - if (iphlpapi == NULL) > - { > - return GetLastError(); > - } > - > - DeleteUnicastIpAddressEntry = (DeleteUnicastIpAddressEntryFn) > GetProcAddress(iphlpapi, "DeleteUnicastIpAddressEntry"); > - if (!DeleteUnicastIpAddressEntry) > - { > - return GetLastError(); > - } > - } > - > return DeleteUnicastIpAddressEntry(addr_row); > } > > @@ -612,32 +577,6 @@ HandleAddressMessage(address_message_t *msg, > undo_lists_t *lists) > PMIB_UNICASTIPADDRESS_ROW addr_row; > BOOL add = msg->header.type == msg_add_address; > > - typedef NETIOAPI_API (*CreateUnicastIpAddressEntryFn) (const > PMIB_UNICASTIPADDRESS_ROW); > - typedef NETIOAPI_API (*InitializeUnicastIpAddressEntryFn) > (PMIB_UNICASTIPADDRESS_ROW); > - static CreateUnicastIpAddressEntryFn CreateUnicastIpAddressEntry = > NULL; > - static InitializeUnicastIpAddressEntryFn > InitializeUnicastIpAddressEntry = NULL; > - > - if (!CreateUnicastIpAddressEntry || !InitializeUnicastIpAddressEntry) > - { > - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); > - if (iphlpapi == NULL) > - { > - return GetLastError(); > - } > - > - CreateUnicastIpAddressEntry = (CreateUnicastIpAddressEntryFn) > GetProcAddress(iphlpapi, "CreateUnicastIpAddressEntry"); > - if (!CreateUnicastIpAddressEntry) > - { > - return GetLastError(); > - } > - > - InitializeUnicastIpAddressEntry = (InitializeUnicastIpAddressEntryFn) > GetProcAddress(iphlpapi, "InitializeUnicastIpAddressEntry"); > - if (!InitializeUnicastIpAddressEntry) > - { > - return GetLastError(); > - } > - } > - > addr_row = malloc(sizeof(*addr_row)); > if (addr_row == NULL) > { > @@ -706,24 +645,6 @@ CmpRoute(LPVOID item, LPVOID route) > static DWORD > DeleteRoute(PMIB_IPFORWARD_ROW2 fwd_row) > { > - typedef NETIOAPI_API (*DeleteIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2); > - static DeleteIpForwardEntry2Fn DeleteIpForwardEntry2 = NULL; > - > - if (!DeleteIpForwardEntry2) > - { > - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); > - if (iphlpapi == NULL) > - { > - return GetLastError(); > - } > - > - DeleteIpForwardEntry2 = (DeleteIpForwardEntry2Fn) > GetProcAddress(iphlpapi, "DeleteIpForwardEntry2"); > - if (!DeleteIpForwardEntry2) > - { > - return GetLastError(); > - } > - } > - > return DeleteIpForwardEntry2(fwd_row); > } > > @@ -734,24 +655,6 @@ HandleRouteMessage(route_message_t *msg, > undo_lists_t *lists) > PMIB_IPFORWARD_ROW2 fwd_row; > BOOL add = msg->header.type == msg_add_route; > > - typedef NETIOAPI_API (*CreateIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2); > - static CreateIpForwardEntry2Fn CreateIpForwardEntry2 = NULL; > - > - if (!CreateIpForwardEntry2) > - { > - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); > - if (iphlpapi == NULL) > - { > - return GetLastError(); > - } > - > - CreateIpForwardEntry2 = (CreateIpForwardEntry2Fn) > GetProcAddress(iphlpapi, "CreateIpForwardEntry2"); > - if (!CreateIpForwardEntry2) > - { > - return GetLastError(); > - } > - } > - > fwd_row = malloc(sizeof(*fwd_row)); > if (fwd_row == NULL) > { > @@ -820,36 +723,12 @@ out: > static DWORD > HandleFlushNeighborsMessage(flush_neighbors_message_t *msg) > { > - typedef NETIOAPI_API (*FlushIpNetTable2Fn) (ADDRESS_FAMILY, > NET_IFINDEX); > - static FlushIpNetTable2Fn flush_fn = NULL; > - > if (msg->family == AF_INET) > { > return FlushIpNetTable(msg->iface.index); > } > > - if (!flush_fn) > - { > - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); > - if (iphlpapi == NULL) > - { > - return GetLastError(); > - } > - > - flush_fn = (FlushIpNetTable2Fn) GetProcAddress(iphlpapi, > "FlushIpNetTable2"); > - if (!flush_fn) > - { > - if (GetLastError() == ERROR_PROC_NOT_FOUND) > - { > - return WSAEPFNOSUPPORT; > - } > - else > - { > - return GetLastError(); > - } > - } > - } > - return flush_fn(msg->family, msg->iface.index); > + return FlushIpNetTable2(msg->family, msg->iface.index); > } > Looks good and cross-compiles without issues. ACK Selva <div dir="ltr">Hi,<div><br></div><div>Note to self: this is v2 of [PATCH 05/13]</div><div><div class="gmail_extra"><a href="https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15589.html" target="_blank">https://www.mail-archive.com/o<wbr>penvpn-devel@lists.sourceforge<wbr>.net/msg15589.html</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 12, 2017 at 4:07 AM, Simon Rozman <span dir="ltr"><<a href="mailto:simon@rozman.si" target="_blank">simon@rozman.si</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dynamically locating API function addresses at run-time using<br> GetProcAddress() was a leftover from the early days of the interactive<br> service development. It was required before `NTDDI_VERSION` was raised<br> from Windows XP to Windows Vista.<br> <br> After NTDDI_VERSION API level was raised to NTDDI_VISTA, the direct<br> calling of Vista introduced API functions is possible and much<br> simpler.<br> <br> This patch simplifies the code while in the same time it removes<br> controversial function type definitions that caused interactive service not to compile on MSVC.<br> ---<br> src/openvpnserv/interactive.c | 123 +-----------------------------<wbr>------------<br> 1 file changed, 1 insertion(+), 122 deletions(-)<br> <br> diff --git a/src/openvpnserv/interactive.<wbr>c b/src/openvpnserv/interactive.<wbr>c<br> index a060a06..bb8c5f6 100644<br> --- a/src/openvpnserv/interactive.<wbr>c<br> +++ b/src/openvpnserv/interactive.<wbr>c<br> @@ -549,23 +549,6 @@ InterfaceLuid(const char *iface_name, PNET_LUID luid)<br> LPWSTR wide_name;<br> int n;<br> <br> - typedef NETIO_STATUS WINAPI (*ConvertInterfaceAliasToLuidF<wbr>n) (LPCWSTR, PNET_LUID);<br> - static ConvertInterfaceAliasToLuidFn ConvertInterfaceAliasToLuid = NULL;<br> - if (!ConvertInterfaceAliasToLuid)<br> - {<br> - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi<wbr>.dll"));<br> - if (iphlpapi == NULL)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - ConvertInterfaceAliasToLuid = (ConvertInterfaceAliasToLuidFn<wbr>) GetProcAddress(iphlpapi, "ConvertInterfaceAliasToLuid")<wbr>;<br> - if (!ConvertInterfaceAliasToLuid)<br> - {<br> - return GetLastError();<br> - }<br> - }<br> -<br> n = MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, NULL, 0);<br> wide_name = malloc(n * sizeof(WCHAR));</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, wide_name, n);<br></blockquote><div><br></div><div>Not a fault of this patch, but malloc's return value not checked... Let's</div><div>address that in a separate patch. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">@@ -584,24 +567,6 @@ CmpAddress(LPVOID item, LPVOID address)<br> static DWORD<br> DeleteAddress(PMIB_UNICASTIPA<wbr>DDRESS_ROW addr_row)<br> {<br> - typedef NETIOAPI_API (*DeleteUnicastIpAddressEntryF<wbr>n) (const PMIB_UNICASTIPADDRESS_ROW);<br> - static DeleteUnicastIpAddressEntryFn DeleteUnicastIpAddressEntry = NULL;<br> -<br> - if (!DeleteUnicastIpAddressEntry)<br> - {<br> - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi<wbr>.dll"));<br> - if (iphlpapi == NULL)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - DeleteUnicastIpAddressEntry = (DeleteUnicastIpAddressEntryFn<wbr>) GetProcAddress(iphlpapi, "DeleteUnicastIpAddressEntry")<wbr>;<br> - if (!DeleteUnicastIpAddressEntry)<br> - {<br> - return GetLastError();<br> - }<br> - }<br> -<br> return DeleteUnicastIpAddressEntry(ad<wbr>dr_row);<br> }<br> <br> @@ -612,32 +577,6 @@ HandleAddressMessage(address_m<wbr>essage_t *msg, undo_lists_t *lists)<br> PMIB_UNICASTIPADDRESS_ROW addr_row;<br> BOOL add = msg->header.type == msg_add_address;<br> <br> - typedef NETIOAPI_API (*CreateUnicastIpAddressEntryF<wbr>n) (const PMIB_UNICASTIPADDRESS_ROW);<br> - typedef NETIOAPI_API (*InitializeUnicastIpAddressEn<wbr>tryFn) (PMIB_UNICASTIPADDRESS_ROW);<br> - static CreateUnicastIpAddressEntryFn CreateUnicastIpAddressEntry = NULL;<br> - static InitializeUnicastIpAddressEntr<wbr>yFn InitializeUnicastIpAddressEntr<wbr>y = NULL;<br> -<br> - if (!CreateUnicastIpAddressEntry || !InitializeUnicastIpAddressEnt<wbr>ry)<br> - {<br> - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi<wbr>.dll"));<br> - if (iphlpapi == NULL)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - CreateUnicastIpAddressEntry = (CreateUnicastIpAddressEntryFn<wbr>) GetProcAddress(iphlpapi, "CreateUnicastIpAddressEntry")<wbr>;<br> - if (!CreateUnicastIpAddressEntry)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - InitializeUnicastIpAddressEntr<wbr>y = (InitializeUnicastIpAddressEnt<wbr>ryFn) GetProcAddress(iphlpapi, "InitializeUnicastIpAddressEnt<wbr>ry");<br> - if (!InitializeUnicastIpAddressEn<wbr>try)<br> - {<br> - return GetLastError();<br> - }<br> - }<br> -<br> addr_row = malloc(sizeof(*addr_row));<br> if (addr_row == NULL)<br> {<br> @@ -706,24 +645,6 @@ CmpRoute(LPVOID item, LPVOID route)<br> static DWORD<br> DeleteRoute(PMIB_IPFORWARD_RO<wbr>W2 fwd_row)<br> {<br> - typedef NETIOAPI_API (*DeleteIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2);<br> - static DeleteIpForwardEntry2Fn DeleteIpForwardEntry2 = NULL;<br> -<br> - if (!DeleteIpForwardEntry2)<br> - {<br> - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi<wbr>.dll"));<br> - if (iphlpapi == NULL)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - DeleteIpForwardEntry2 = (DeleteIpForwardEntry2Fn) GetProcAddress(iphlpapi, "DeleteIpForwardEntry2");<br> - if (!DeleteIpForwardEntry2)<br> - {<br> - return GetLastError();<br> - }<br> - }<br> -<br> return DeleteIpForwardEntry2(fwd_row)<wbr>;<br> }<br> <br> @@ -734,24 +655,6 @@ HandleRouteMessage(route_messa<wbr>ge_t *msg, undo_lists_t *lists)<br> PMIB_IPFORWARD_ROW2 fwd_row;<br> BOOL add = msg->header.type == msg_add_route;<br> <br> - typedef NETIOAPI_API (*CreateIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2);<br> - static CreateIpForwardEntry2Fn CreateIpForwardEntry2 = NULL;<br> -<br> - if (!CreateIpForwardEntry2)<br> - {<br> - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi<wbr>.dll"));<br> - if (iphlpapi == NULL)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - CreateIpForwardEntry2 = (CreateIpForwardEntry2Fn) GetProcAddress(iphlpapi, "CreateIpForwardEntry2");<br> - if (!CreateIpForwardEntry2)<br> - {<br> - return GetLastError();<br> - }<br> - }<br> -<br> fwd_row = malloc(sizeof(*fwd_row));<br> if (fwd_row == NULL)<br> {<br> @@ -820,36 +723,12 @@ out:<br> static DWORD<br> HandleFlushNeighborsMessage(f<wbr>lush_neighbors_message_t *msg)<br> {<br> - typedef NETIOAPI_API (*FlushIpNetTable2Fn) (ADDRESS_FAMILY, NET_IFINDEX);<br> - static FlushIpNetTable2Fn flush_fn = NULL;<br> -<br> if (msg->family == AF_INET)<br> {<br> return FlushIpNetTable(msg->iface.ind<wbr>ex);<br> }<br> <br> - if (!flush_fn)<br> - {<br> - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi<wbr>.dll"));<br> - if (iphlpapi == NULL)<br> - {<br> - return GetLastError();<br> - }<br> -<br> - flush_fn = (FlushIpNetTable2Fn) GetProcAddress(iphlpapi, "FlushIpNetTable2");<br> - if (!flush_fn)<br> - {<br> - if (GetLastError() == ERROR_PROC_NOT_FOUND)<br> - {<br> - return WSAEPFNOSUPPORT;<br> - }<br> - else<br> - {<br> - return GetLastError();<br> - }<br> - }<br> - }<br> - return flush_fn(msg->family, msg->iface.index);<br> + return FlushIpNetTable2(msg->family, msg->iface.index);<br> }<br></blockquote><div><br></div><div>Looks good and cross-compiles without issues.</div><div><br></div><div>ACK</div><div><br></div><div>Selva</div></div></div></div></div> ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
I like patches that *remove* lots of lines of code :-) Your patch has been applied to the master and release/2.4 branch. commit a5d73667ffebea93960c135322aa3a8d0fd70d7a (master) commit c5f0ccf1376b6c7e1fe58c87a67b009be3ac9361 (release/2.4) Author: Simon Rozman Date: Thu Oct 12 10:07:20 2017 +0200 Simplify iphlpapi.dll API calls Acked-by: Selva Nair <selva.nair@gmail.com> Message-Id: <20171012080720.7764-1-simon@rozman.si> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15614.html Signed-off-by: Gert Doering <gert@greenie.muc.de> -- kind regards, Gert Doering ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index a060a06..bb8c5f6 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -549,23 +549,6 @@ InterfaceLuid(const char *iface_name, PNET_LUID luid) LPWSTR wide_name; int n; - typedef NETIO_STATUS WINAPI (*ConvertInterfaceAliasToLuidFn) (LPCWSTR, PNET_LUID); - static ConvertInterfaceAliasToLuidFn ConvertInterfaceAliasToLuid = NULL; - if (!ConvertInterfaceAliasToLuid) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - ConvertInterfaceAliasToLuid = (ConvertInterfaceAliasToLuidFn) GetProcAddress(iphlpapi, "ConvertInterfaceAliasToLuid"); - if (!ConvertInterfaceAliasToLuid) - { - return GetLastError(); - } - } - n = MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, NULL, 0); wide_name = malloc(n * sizeof(WCHAR)); MultiByteToWideChar(CP_UTF8, 0, iface_name, -1, wide_name, n); @@ -584,24 +567,6 @@ CmpAddress(LPVOID item, LPVOID address) static DWORD DeleteAddress(PMIB_UNICASTIPADDRESS_ROW addr_row) { - typedef NETIOAPI_API (*DeleteUnicastIpAddressEntryFn) (const PMIB_UNICASTIPADDRESS_ROW); - static DeleteUnicastIpAddressEntryFn DeleteUnicastIpAddressEntry = NULL; - - if (!DeleteUnicastIpAddressEntry) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - DeleteUnicastIpAddressEntry = (DeleteUnicastIpAddressEntryFn) GetProcAddress(iphlpapi, "DeleteUnicastIpAddressEntry"); - if (!DeleteUnicastIpAddressEntry) - { - return GetLastError(); - } - } - return DeleteUnicastIpAddressEntry(addr_row); } @@ -612,32 +577,6 @@ HandleAddressMessage(address_message_t *msg, undo_lists_t *lists) PMIB_UNICASTIPADDRESS_ROW addr_row; BOOL add = msg->header.type == msg_add_address; - typedef NETIOAPI_API (*CreateUnicastIpAddressEntryFn) (const PMIB_UNICASTIPADDRESS_ROW); - typedef NETIOAPI_API (*InitializeUnicastIpAddressEntryFn) (PMIB_UNICASTIPADDRESS_ROW); - static CreateUnicastIpAddressEntryFn CreateUnicastIpAddressEntry = NULL; - static InitializeUnicastIpAddressEntryFn InitializeUnicastIpAddressEntry = NULL; - - if (!CreateUnicastIpAddressEntry || !InitializeUnicastIpAddressEntry) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - CreateUnicastIpAddressEntry = (CreateUnicastIpAddressEntryFn) GetProcAddress(iphlpapi, "CreateUnicastIpAddressEntry"); - if (!CreateUnicastIpAddressEntry) - { - return GetLastError(); - } - - InitializeUnicastIpAddressEntry = (InitializeUnicastIpAddressEntryFn) GetProcAddress(iphlpapi, "InitializeUnicastIpAddressEntry"); - if (!InitializeUnicastIpAddressEntry) - { - return GetLastError(); - } - } - addr_row = malloc(sizeof(*addr_row)); if (addr_row == NULL) { @@ -706,24 +645,6 @@ CmpRoute(LPVOID item, LPVOID route) static DWORD DeleteRoute(PMIB_IPFORWARD_ROW2 fwd_row) { - typedef NETIOAPI_API (*DeleteIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2); - static DeleteIpForwardEntry2Fn DeleteIpForwardEntry2 = NULL; - - if (!DeleteIpForwardEntry2) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - DeleteIpForwardEntry2 = (DeleteIpForwardEntry2Fn) GetProcAddress(iphlpapi, "DeleteIpForwardEntry2"); - if (!DeleteIpForwardEntry2) - { - return GetLastError(); - } - } - return DeleteIpForwardEntry2(fwd_row); } @@ -734,24 +655,6 @@ HandleRouteMessage(route_message_t *msg, undo_lists_t *lists) PMIB_IPFORWARD_ROW2 fwd_row; BOOL add = msg->header.type == msg_add_route; - typedef NETIOAPI_API (*CreateIpForwardEntry2Fn) (PMIB_IPFORWARD_ROW2); - static CreateIpForwardEntry2Fn CreateIpForwardEntry2 = NULL; - - if (!CreateIpForwardEntry2) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - CreateIpForwardEntry2 = (CreateIpForwardEntry2Fn) GetProcAddress(iphlpapi, "CreateIpForwardEntry2"); - if (!CreateIpForwardEntry2) - { - return GetLastError(); - } - } - fwd_row = malloc(sizeof(*fwd_row)); if (fwd_row == NULL) { @@ -820,36 +723,12 @@ out: static DWORD HandleFlushNeighborsMessage(flush_neighbors_message_t *msg) { - typedef NETIOAPI_API (*FlushIpNetTable2Fn) (ADDRESS_FAMILY, NET_IFINDEX); - static FlushIpNetTable2Fn flush_fn = NULL; - if (msg->family == AF_INET) { return FlushIpNetTable(msg->iface.index); } - if (!flush_fn) - { - HMODULE iphlpapi = GetModuleHandle(TEXT("iphlpapi.dll")); - if (iphlpapi == NULL) - { - return GetLastError(); - } - - flush_fn = (FlushIpNetTable2Fn) GetProcAddress(iphlpapi, "FlushIpNetTable2"); - if (!flush_fn) - { - if (GetLastError() == ERROR_PROC_NOT_FOUND) - { - return WSAEPFNOSUPPORT; - } - else - { - return GetLastError(); - } - } - } - return flush_fn(msg->family, msg->iface.index); + return FlushIpNetTable2(msg->family, msg->iface.index); } static void