Author: cgutman
Date: Mon Aug 3 04:15:17 2009
New Revision: 42356
URL:
http://svn.reactos.org/svn/reactos?rev=42356&view=rev
Log:
- 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
Modified:
trunk/reactos/base/applications/network/ping/ping.c
Modified: trunk/reactos/base/applications/network/ping/ping.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/network/…
==============================================================================
--- trunk/reactos/base/applications/network/ping/ping.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/network/ping/ping.c [iso-8859-1] Mon Aug 3 04:15:17
2009
@@ -437,6 +437,14 @@
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 @@
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());
+ }
+ 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 FALSE;
- }
- Status = 0;
- }
-
- 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++;
- }
+ return TRUE;
+ }
+
+ } while (!DecodeResponse(Buffer, Status, (PSOCKADDR_IN)&From));
GlobalFree(Buffer);
return TRUE;