DataSize = GetULONG2(&argv[i][2], argv[i + 1], &i);
if (DataSize > ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET))
{
- printf("Bad value for option -l, valid range is from 0 to %I64d.\n",
- ICMP_MAXSIZE - sizeof(ICMP_ECHO_PACKET));
+ printf("Bad value for option -l, valid range is from 0 to %d.\n",
+ ICMP_MAXSIZE - (int)sizeof(ICMP_ECHO_PACKET));
return FALSE;
}
break;
Target.sin_family = AF_INET;
TargetIP = inet_ntoa(Target.sin_addr);
- CurrentSeqNum = 0;
+ CurrentSeqNum = 1;
SentCount = 0;
LostCount = 0;
MinRTT.QuadPart = 0;
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);
}
- printf("Reply from %s: bytes=%I64d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr),
- size - IphLength - sizeof(ICMP_ECHO_PACKET), Sign, Time, IpHeader->TTL);
+ printf("Reply from %s: bytes=%d time%s%s TTL=%d\n", inet_ntoa(from->sin_addr),
+ size - IphLength - (int)sizeof(ICMP_ECHO_PACKET), Sign, Time, IpHeader->TTL);
if (RelativeTime.QuadPart < MinRTT.QuadPart || !MinRTTSet)
{
MinRTT.QuadPart = RelativeTime.QuadPart;
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)
+ }
+ else
+ LostCount++;
+ if (Status == SOCKET_ERROR)
{
- printf("Could not receive data (%d).\n", WSAGetLastError());
- GlobalFree(Buffer);
- return FALSE;
+ if (WSAGetLastError() != WSAETIMEDOUT)
+ {
+ printf("Could not receive data (%d).\n", WSAGetLastError());
+ GlobalFree(Buffer);
+ return FALSE;
+ }
+ Status = 0;
}
- 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;