mirror of
https://github.com/reactos/reactos.git
synced 2025-05-07 02:41:22 +00:00
- Keep waiting for a reply if we get one that is not ours or invalid
- Make sure the packet we got is from our target otherwise discard it svn path=/trunk/; revision=42356
This commit is contained in:
parent
b85fb3bd9f
commit
3ced893fd0
1 changed files with 36 additions and 32 deletions
|
@ -437,6 +437,14 @@ static BOOL DecodeResponse(PCHAR buffer, UINT size, PSOCKADDR_IN from)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (from->sin_addr.s_addr != Target.sin_addr.s_addr)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
printf("Bad source address (%s should be %s)\n", inet_ntoa(from->sin_addr), inet_ntoa(Target.sin_addr));
|
||||
#endif /* !NDEBUG */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
QueryTime(&LargeTime);
|
||||
|
||||
RelativeTime.QuadPart = (LargeTime.QuadPart - Icmp->Timestamp.QuadPart);
|
||||
|
@ -543,44 +551,40 @@ static BOOL Ping(VOID)
|
|||
Timeval.tv_sec = Timeout / 1000;
|
||||
Timeval.tv_usec = Timeout % 1000;
|
||||
|
||||
Status = select(0, &Fds, NULL, NULL, &Timeval);
|
||||
if ((Status != SOCKET_ERROR) && (Status != 0))
|
||||
{
|
||||
Length = sizeof(From);
|
||||
Status = recvfrom(IcmpSock, Buffer, Size, 0, &From, &Length);
|
||||
do {
|
||||
Status = select(0, &Fds, NULL, NULL, &Timeval);
|
||||
if ((Status != SOCKET_ERROR) && (Status != 0))
|
||||
{
|
||||
Length = sizeof(From);
|
||||
Status = recvfrom(IcmpSock, Buffer, Size, 0, &From, &Length);
|
||||
|
||||
#ifndef NDEBUG
|
||||
printf("Received packet\n");
|
||||
DisplayBuffer(Buffer, Status);
|
||||
printf("\n");
|
||||
printf("Received packet\n");
|
||||
DisplayBuffer(Buffer, Status);
|
||||
printf("\n");
|
||||
#endif /* !NDEBUG */
|
||||
}
|
||||
else
|
||||
LostCount++;
|
||||
if (Status == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAETIMEDOUT)
|
||||
{
|
||||
printf("Could not receive data (%d).\n", WSAGetLastError());
|
||||
GlobalFree(Buffer);
|
||||
return FALSE;
|
||||
}
|
||||
Status = 0;
|
||||
}
|
||||
else
|
||||
LostCount++;
|
||||
if (Status == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() != WSAETIMEDOUT)
|
||||
{
|
||||
printf("Could not receive data (%d).\n", WSAGetLastError());
|
||||
GlobalFree(Buffer);
|
||||
return FALSE;
|
||||
}
|
||||
Status = 0;
|
||||
}
|
||||
|
||||
if (Status == 0)
|
||||
{
|
||||
printf("Request timed out.\n");
|
||||
GlobalFree(Buffer);
|
||||
return TRUE;
|
||||
}
|
||||
if (Status == 0)
|
||||
{
|
||||
printf("Request timed out.\n");
|
||||
GlobalFree(Buffer);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (!DecodeResponse(Buffer, Status, (PSOCKADDR_IN)&From))
|
||||
{
|
||||
/* FIXME: Wait again as it could be another ICMP message type */
|
||||
printf("Request timed out (incomplete datagram received).\n");
|
||||
LostCount++;
|
||||
}
|
||||
} while (!DecodeResponse(Buffer, Status, (PSOCKADDR_IN)&From));
|
||||
|
||||
GlobalFree(Buffer);
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in a new issue