Warning("[ICMP ] Code == %i for ICMP Echo Reply, should be 0", hdr->Code);
return ;
}
- if(hdr->ID != ~hdr->Sequence) {
+ if(hdr->ID != (Uint16)~hdr->Sequence) {
Warning("[ICMP ] ID and Sequence values do not match");
- return ;
+ //return ;
}
gICMP_PingSlots[hdr->ID].bArrived = 1;
break;
+ // -- 3: Destination Unreachable
+ case ICMP_UNREACHABLE:
+ switch(hdr->Code)
+ {
+ case 3: // Port Unreachable
+ Log("[ICMP ] Destination Unreachable (Port Unreachable)");
+ break;
+ default:
+ Log("[ICMP ] Destination Unreachable (Code %i)", hdr->Code);
+ break;
+ }
+// IPv4_Unreachable( Interface, hdr->Code, htons(hdr->Length)-sizeof(tICMPHeader), hdr->Data );
+ break;
+
// -- 8: Echo Request
case ICMP_ECHOREQ:
if(hdr->Code != 0) {
Log("[ICMP ] Checksum = 0x%04x", hdr->Checksum);
IPv4_SendPacket(Interface, *(tIPv4*)Address, 1, ntohs(hdr->Sequence), Length, hdr);
break;
+ default:
+ break;
}
}
*/
int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
{
- //Sint64 ts;
+ Sint64 ts;
+ Sint64 end;
char buf[32] = "\x8\0\0\0\0\0\0\0Acess2 I"
"P/TCP Stack 1.0\0";
tICMPHeader *hdr = (void*)buf;
{
if(gICMP_PingSlots[i].Interface == NULL) break;
}
- if(gICMP_PingSlots[i].Interface == NULL) break;
+ if( i < PING_SLOTS ) break;
Threads_Yield();
}
gICMP_PingSlots[i].Interface = Interface;
hdr->Checksum = htons( IPv4_Checksum(hdr, sizeof(buf)) );
IPv4_SendPacket(Interface, Addr, 1, i, sizeof(buf), buf);
- return -1;
+ ts = now();
+ end = ts + Interface->TimeoutDelay;
+ while( !gICMP_PingSlots[i].bArrived && now() < end) Threads_Yield();
+
+ ts = now() - ts;
+ if(ts > Interface->TimeoutDelay)
+ return -1;
+
+ return (int)ts;
}