https://git.reactos.org/?p=reactos.git;a=commitdiff;h=906fdf9ccb075301a2ae8…
commit 906fdf9ccb075301a2ae85ab0979abf7a20bd2ab
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Fri Jan 26 21:38:47 2018 +0300
Commit: Ged Murphy <gedmurphy(a)reactos.org>
CommitDate: Fri Jan 26 18:38:47 2018 +0000
[PING] Fix error handling and response address decoding (#318)
- Host/net unreachable error should be obtained from EchoReply->Status
- Use GetNameInfoW to decode actual response addresses (borrowed from tracert code)
CORE-14241 #resolve
---
base/applications/network/ping/ping.c | 67 ++++++++++++++++++++++++++++++-----
1 file changed, 58 insertions(+), 9 deletions(-)
diff --git a/base/applications/network/ping/ping.c
b/base/applications/network/ping/ping.c
index bbeafa6c88..dd1262eac0 100644
--- a/base/applications/network/ping/ping.c
+++ b/base/applications/network/ping/ping.c
@@ -479,14 +479,6 @@ Ping(void)
Status = GetLastError();
switch (Status)
{
- case IP_DEST_HOST_UNREACHABLE:
- ConResPrintf(StdOut, IDS_DEST_HOST_UNREACHABLE);
- break;
-
- case IP_DEST_NET_UNREACHABLE:
- ConResPrintf(StdOut, IDS_DEST_NET_UNREACHABLE);
- break;
-
case IP_REQ_TIMED_OUT:
ConResPrintf(StdOut, IDS_REQUEST_TIMED_OUT);
break;
@@ -498,16 +490,40 @@ Ping(void)
}
else
{
+ SOCKADDR_IN6 SockAddrIn6;
+ SOCKADDR_IN SockAddrIn;
+ PSOCKADDR SockAddr;
+ socklen_t Size;
+
EchosReceived++;
- ConResPrintf(StdOut, IDS_REPLY_FROM, Address);
+ ZeroMemory(&SockAddrIn, sizeof(SockAddrIn));
+ ZeroMemory(&SockAddrIn6, sizeof(SockAddrIn6));
if (Family == AF_INET6)
{
PICMPV6_ECHO_REPLY pEchoReply;
+ PIPV6_ADDRESS_EX Ipv6Addr;
pEchoReply = (PICMPV6_ECHO_REPLY)ReplyBuffer;
+ Ipv6Addr = (PIPV6_ADDRESS_EX)&pEchoReply->Address;
+ SockAddrIn6.sin6_family = AF_INET6;
+ CopyMemory(SockAddrIn6.sin6_addr.u.Word, Ipv6Addr->sin6_addr,
sizeof(SockAddrIn6.sin6_addr));
+ //SockAddrIn6.sin6_addr = Ipv6Addr->sin6_addr;
+ SockAddr = (PSOCKADDR)&SockAddrIn6;
+ Size = sizeof(SOCKADDR_IN6);
+
+ GetNameInfoW(SockAddr,
+ Size,
+ Address,
+ NI_MAXHOST,
+ NULL,
+ 0,
+ NI_NUMERICHOST);
+
+ ConResPrintf(StdOut, IDS_REPLY_FROM, Address);
+
switch (pEchoReply->Status)
{
case IP_SUCCESS:
@@ -531,6 +547,14 @@ Ping(void)
break;
}
+ case IP_DEST_NET_UNREACHABLE:
+ ConResPrintf(StdOut, IDS_DEST_NET_UNREACHABLE);
+ break;
+
+ case IP_DEST_HOST_UNREACHABLE:
+ ConResPrintf(StdOut, IDS_DEST_HOST_UNREACHABLE);
+ break;
+
case IP_TTL_EXPIRED_TRANSIT:
ConResPrintf(StdOut, IDS_TTL_EXPIRED);
break;
@@ -543,9 +567,26 @@ Ping(void)
else
{
PICMP_ECHO_REPLY pEchoReply;
+ IPAddr *IP4Addr;
pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
+ IP4Addr = (IPAddr *)&pEchoReply->Address;
+ SockAddrIn.sin_family = AF_INET;
+ SockAddrIn.sin_addr.S_un.S_addr = *IP4Addr;
+ SockAddr = (PSOCKADDR)&SockAddrIn;
+ Size = sizeof(SOCKADDR_IN);
+
+ GetNameInfoW(SockAddr,
+ Size,
+ Address,
+ NI_MAXHOST,
+ NULL,
+ 0,
+ NI_NUMERICHOST);
+
+ ConResPrintf(StdOut, IDS_REPLY_FROM, Address);
+
switch (pEchoReply->Status)
{
case IP_SUCCESS:
@@ -571,6 +612,14 @@ Ping(void)
break;
}
+ case IP_DEST_NET_UNREACHABLE:
+ ConResPrintf(StdOut, IDS_DEST_NET_UNREACHABLE);
+ break;
+
+ case IP_DEST_HOST_UNREACHABLE:
+ ConResPrintf(StdOut, IDS_DEST_HOST_UNREACHABLE);
+ break;
+
case IP_TTL_EXPIRED_TRANSIT:
ConResPrintf(StdOut, IDS_TTL_EXPIRED);
break;