-- v2: iphlpapi: Implement GetRTTAndHopCount().
From: Marc-Aurel Zent mzent@codeweavers.com
--- dlls/iphlpapi/iphlpapi_main.c | 50 ++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 7 deletions(-)
diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 9c7582b71fb..9c451500fa5 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -2781,15 +2781,51 @@ DWORD WINAPI GetPerAdapterInfo( ULONG index, IP_PER_ADAPTER_INFO *info, ULONG *s * RETURNS * Success: TRUE * Failure: FALSE - * - * FIXME - * Stub, returns FALSE. */ -BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT) +BOOL WINAPI GetRTTAndHopCount( IPAddr dest_ip_address, ULONG *hop_count, ULONG max_hops, ULONG *rtt ) { - FIXME("(DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p): stub\n", - DestIpAddress, HopCount, MaxHops, RTT); - return FALSE; + char send_buffer[0x20] = { 0xDE, 0xAD, 0xBE, 0xEF }; + char receive_buffer[sizeof(ICMP_ECHO_REPLY) + sizeof(send_buffer)]; + const DWORD timeout = 5000; + DWORD replies; + IP_OPTION_INFORMATION send_options = { 0 }; + ICMP_ECHO_REPLY *reply; + HANDLE icmp_handle; + + TRACE( "(dest_ip_address 0x%08lx, hop_count %p, max_hops %ld, rtt %p)\n", + dest_ip_address, hop_count, max_hops, rtt ); + + if (!hop_count || !rtt || dest_ip_address == INADDR_NONE) + return FALSE; + + if ((icmp_handle = IcmpCreateFile()) == INVALID_HANDLE_VALUE) + return FALSE; + + for (send_options.Ttl = 1; send_options.Ttl <= max_hops; send_options.Ttl++) + { + replies = IcmpSendEcho( icmp_handle, dest_ip_address, send_buffer, sizeof(send_buffer), + &send_options, receive_buffer, sizeof(receive_buffer), timeout ); + + if (!replies) + { + if (GetLastError() == IP_TTL_EXPIRED_TRANSIT) continue; + if (GetLastError() == IP_REQ_TIMED_OUT) continue; + break; + } + + reply = (PICMP_ECHO_REPLY)receive_buffer; + + if (reply->Status == IP_SUCCESS) + { + *hop_count = send_options.Ttl; + *rtt = reply->RoundTripTime; + IcmpCloseHandle( icmp_handle ); + return TRUE; + } + } + + IcmpCloseHandle( icmp_handle ); + return FALSE; }
/******************************************************************
On Tue Feb 13 13:25:23 2024 +0000, Marc-Aurel Zent wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/4853/diffs?diff_id=99319&start_sha=fd7d55392e4cc6d6f143404342c68265a4d6ba7e#f5177724934620bf34a61d786cf373a3caac591d_2786_2785)
Thanks for looking over it, should be fixed now.
This merge request was approved by Huw Davies.