From 6655f3dc842b1d2221d417b205baaba1d156a3fc Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sun, 29 Nov 2015 18:54:40 +0100 Subject: [PATCH] Added patch to ensure default route IP addresses are returned first in gethostbyname. --- README.md | 4 +- patches/patchinstall.sh | 20 ++++ ...fault-route-IP-addresses-are-returne.patch | 99 +++++++++++++++++++ patches/ws2_32-Sort_default_route/definition | 2 + staging/changelog | 2 + 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 patches/ws2_32-Sort_default_route/0001-ws2_32-Ensure-default-route-IP-addresses-are-returne.patch create mode 100644 patches/ws2_32-Sort_default_route/definition diff --git a/README.md b/README.md index 20cd0152..4649e972 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,15 @@ Wine. All those differences are also documented on the Included bug fixes and improvements ----------------------------------- -**Bug fixes and features included in the next upcoming release [10]:** +**Bug fixes and features included in the next upcoming release [12]:** * Add information for delayed end of DST in Europe/Istanbul * Allow to set debug registers separately in NtSetContextThread ([Wine Bug #39454](https://bugs.winehq.org/show_bug.cgi?id=39454)) * Also send WM_CAPTURECHANGE when capture has not changed ([Wine Bug #13683](https://bugs.winehq.org/show_bug.cgi?id=13683)) * Check handle type for HSPFILEQ handles ([Wine Bug #12332](https://bugs.winehq.org/show_bug.cgi?id=12332)) +* Ensure default route IP addresses are returned first in gethostbyname ([Wine Bug #22819](https://bugs.winehq.org/show_bug.cgi?id=22819)) * Fix font loading in Capella ([Wine Bug #12377](https://bugs.winehq.org/show_bug.cgi?id=12377)) +* Fix issue causing applications to report magic loopback address instead of real IP ([Wine Bug #37271](https://bugs.winehq.org/show_bug.cgi?id=37271)) * Ignore socket type for protocol IPPROTO_IPV6 in getaddrinfo * Implement dinput device property DIPROP_USERNAME ([Wine Bug #39667](https://bugs.winehq.org/show_bug.cgi?id=39667)) * Silence repeated FIXME message in surface_cpu_blt diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index e2c477f9..4aa36913 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -339,6 +339,7 @@ patch_enable_all () enable_wpcap_Dynamic_Linking="$1" enable_ws2_32_APC_Performance="$1" enable_ws2_32_Connect_Time="$1" + enable_ws2_32_Sort_default_route="$1" enable_ws2_32_TransmitFile="$1" enable_ws2_32_WSACleanup="$1" enable_ws2_32_WSAPoll="$1" @@ -1131,6 +1132,9 @@ patch_enable () ws2_32-Connect_Time) enable_ws2_32_Connect_Time="$2" ;; + ws2_32-Sort_default_route) + enable_ws2_32_Sort_default_route="$2" + ;; ws2_32-TransmitFile) enable_ws2_32_TransmitFile="$2" ;; @@ -6694,6 +6698,22 @@ if test "$enable_ws2_32_Connect_Time" -eq 1; then ) >> "$patchlist" fi +# Patchset ws2_32-Sort_default_route +# | +# | This patchset fixes the following Wine bugs: +# | * [#22819] Ensure default route IP addresses are returned first in gethostbyname +# | * [#37271] Fix issue causing applications to report magic loopback address instead of real IP +# | +# | Modified files: +# | * dlls/ws2_32/socket.c, dlls/ws2_32/tests/sock.c +# | +if test "$enable_ws2_32_Sort_default_route" -eq 1; then + patch_apply ws2_32-Sort_default_route/0001-ws2_32-Ensure-default-route-IP-addresses-are-returne.patch + ( + echo '+ { "Bruno Jesus", "ws2_32: Ensure default route IP addresses are returned first in gethostbyname.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ws2_32-TransmitFile # | # | Modified files: diff --git a/patches/ws2_32-Sort_default_route/0001-ws2_32-Ensure-default-route-IP-addresses-are-returne.patch b/patches/ws2_32-Sort_default_route/0001-ws2_32-Ensure-default-route-IP-addresses-are-returne.patch new file mode 100644 index 00000000..94edbf1c --- /dev/null +++ b/patches/ws2_32-Sort_default_route/0001-ws2_32-Ensure-default-route-IP-addresses-are-returne.patch @@ -0,0 +1,99 @@ +From d2d862c195527b1cff45f2fedc2bd3f6014f3187 Mon Sep 17 00:00:00 2001 +From: Bruno Jesus <00cpxxx@gmail.com> +Date: Sun, 29 Nov 2015 11:28:28 +0800 +Subject: ws2_32: Ensure default route IP addresses are returned first in + gethostbyname + +Fixes: +https://bugs.winehq.org/show_bug.cgi?id=37271 +https://bugs.winehq.org/show_bug.cgi?id=22819 +--- + dlls/ws2_32/socket.c | 23 +++++++++++++++++------ + dlls/ws2_32/tests/sock.c | 1 - + 2 files changed, 17 insertions(+), 7 deletions(-) + +diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c +index d31f0b4..6877063 100644 +--- a/dlls/ws2_32/socket.c ++++ b/dlls/ws2_32/socket.c +@@ -596,7 +596,7 @@ struct per_thread_data + struct route { + struct in_addr addr; + IF_INDEX interface; +- DWORD metric; ++ DWORD metric, default_route; + }; + + static INT num_startup; /* reference counter */ +@@ -5931,7 +5931,14 @@ struct WS_hostent* WINAPI WS_gethostbyaddr(const char *addr, int len, int type) + */ + static int WS_compare_routes_by_metric_asc(const void *left, const void *right) + { +- return ((const struct route*)left)->metric - ((const struct route*)right)->metric; ++ const struct route *a = left, *b = right; ++ if (a->default_route && b->default_route) ++ return a->default_route - b->default_route; ++ if (a->default_route && !b->default_route) ++ return -1; ++ if (b->default_route && !a->default_route) ++ return 1; ++ return a->metric - b->metric; + } + + /*********************************************************************** +@@ -5948,7 +5955,7 @@ static int WS_compare_routes_by_metric_asc(const void *left, const void *right) + */ + static struct WS_hostent* WS_get_local_ips( char *hostname ) + { +- int numroutes = 0, i, j; ++ int numroutes = 0, i, j, default_routes = 0; + DWORD n; + PIP_ADAPTER_INFO adapters = NULL, k; + struct WS_hostent *hostlist = NULL; +@@ -5975,10 +5982,13 @@ static struct WS_hostent* WS_get_local_ips( char *hostname ) + for (n = 0; n < routes->dwNumEntries; n++) + { + IF_INDEX ifindex; +- DWORD ifmetric; ++ DWORD ifmetric, ifdefault = 0; + BOOL exists = FALSE; + +- if (routes->table[n].u1.ForwardType != MIB_IPROUTE_TYPE_DIRECT) ++ /* Check if this is a default route (there may be more than one) */ ++ if (!routes->table[n].dwForwardDest) ++ ifdefault = ++default_routes; ++ else if (routes->table[n].u1.ForwardType != MIB_IPROUTE_TYPE_DIRECT) + continue; + ifindex = routes->table[n].dwForwardIfIndex; + ifmetric = routes->table[n].dwForwardMetric1; +@@ -5999,13 +6009,14 @@ static struct WS_hostent* WS_get_local_ips( char *hostname ) + goto cleanup; /* Memory allocation error, fail gracefully */ + route_addrs[numroutes].interface = ifindex; + route_addrs[numroutes].metric = ifmetric; ++ route_addrs[numroutes].default_route = ifdefault; + /* If no IP is found in the next step (for whatever reason) + * then fall back to the magic loopback address. + */ + memcpy(&(route_addrs[numroutes].addr.s_addr), magic_loopback_addr, 4); + numroutes++; + } +- if (numroutes == 0) ++ if (numroutes == 0) + goto cleanup; /* No routes, fall back to the Magic IP */ + /* Find the IP address associated with each found interface */ + for (i = 0; i < numroutes; i++) +diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c +index 00fac77..ce09053 100644 +--- a/dlls/ws2_32/tests/sock.c ++++ b/dlls/ws2_32/tests/sock.c +@@ -4545,7 +4545,6 @@ static void test_gethostbyname(void) + } + } + } +-todo_wine + ok (found_default, "failed to find the first IP from gethostbyname!\n"); + + cleanup: +-- +2.6.2 + diff --git a/patches/ws2_32-Sort_default_route/definition b/patches/ws2_32-Sort_default_route/definition new file mode 100644 index 00000000..f06e6e3f --- /dev/null +++ b/patches/ws2_32-Sort_default_route/definition @@ -0,0 +1,2 @@ +Fixes: [22819] Ensure default route IP addresses are returned first in gethostbyname +Fixes: [37271] Fix issue causing applications to report magic loopback address instead of real IP diff --git a/staging/changelog b/staging/changelog index 5c53e024..236bae12 100644 --- a/staging/changelog +++ b/staging/changelog @@ -21,6 +21,8 @@ wine-staging (1.8~rc2) UNRELEASED; urgency=low NtSetContextThread. * Added patch to ignore socket type for protocol IPPROTO_IPV6 in getaddrinfo. * Added patch to implement dinput device property DIPROP_USERNAME. + * Added patch to ensure default route IP addresses are returned first in + gethostbyname. -- Sebastian Lackner Wed, 25 Nov 2015 20:21:46 +0100 wine-staging (1.8~rc1) unstable; urgency=low