mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 22:33:00 +00:00
[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
This commit is contained in:
parent
010c7bfc9b
commit
906fdf9ccb
1 changed files with 58 additions and 9 deletions
|
@ -479,14 +479,6 @@ Ping(void)
|
||||||
Status = GetLastError();
|
Status = GetLastError();
|
||||||
switch (Status)
|
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:
|
case IP_REQ_TIMED_OUT:
|
||||||
ConResPrintf(StdOut, IDS_REQUEST_TIMED_OUT);
|
ConResPrintf(StdOut, IDS_REQUEST_TIMED_OUT);
|
||||||
break;
|
break;
|
||||||
|
@ -498,16 +490,40 @@ Ping(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
SOCKADDR_IN6 SockAddrIn6;
|
||||||
|
SOCKADDR_IN SockAddrIn;
|
||||||
|
PSOCKADDR SockAddr;
|
||||||
|
socklen_t Size;
|
||||||
|
|
||||||
EchosReceived++;
|
EchosReceived++;
|
||||||
|
|
||||||
ConResPrintf(StdOut, IDS_REPLY_FROM, Address);
|
ZeroMemory(&SockAddrIn, sizeof(SockAddrIn));
|
||||||
|
ZeroMemory(&SockAddrIn6, sizeof(SockAddrIn6));
|
||||||
|
|
||||||
if (Family == AF_INET6)
|
if (Family == AF_INET6)
|
||||||
{
|
{
|
||||||
PICMPV6_ECHO_REPLY pEchoReply;
|
PICMPV6_ECHO_REPLY pEchoReply;
|
||||||
|
PIPV6_ADDRESS_EX Ipv6Addr;
|
||||||
|
|
||||||
pEchoReply = (PICMPV6_ECHO_REPLY)ReplyBuffer;
|
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)
|
switch (pEchoReply->Status)
|
||||||
{
|
{
|
||||||
case IP_SUCCESS:
|
case IP_SUCCESS:
|
||||||
|
@ -531,6 +547,14 @@ Ping(void)
|
||||||
break;
|
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:
|
case IP_TTL_EXPIRED_TRANSIT:
|
||||||
ConResPrintf(StdOut, IDS_TTL_EXPIRED);
|
ConResPrintf(StdOut, IDS_TTL_EXPIRED);
|
||||||
break;
|
break;
|
||||||
|
@ -543,9 +567,26 @@ Ping(void)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PICMP_ECHO_REPLY pEchoReply;
|
PICMP_ECHO_REPLY pEchoReply;
|
||||||
|
IPAddr *IP4Addr;
|
||||||
|
|
||||||
pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer;
|
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)
|
switch (pEchoReply->Status)
|
||||||
{
|
{
|
||||||
case IP_SUCCESS:
|
case IP_SUCCESS:
|
||||||
|
@ -571,6 +612,14 @@ Ping(void)
|
||||||
break;
|
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:
|
case IP_TTL_EXPIRED_TRANSIT:
|
||||||
ConResPrintf(StdOut, IDS_TTL_EXPIRED);
|
ConResPrintf(StdOut, IDS_TTL_EXPIRED);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue