13 void ICMP_Initialise();
14 void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer);
18 tInterface *Interface;
20 } gICMP_PingSlots[PING_SLOTS];
24 * \fn void ICMP_Initialise()
25 * \brief Initialise the ICMP Layer
27 void ICMP_Initialise()
29 IPv4_RegisterCallback(IP4PROT_ICMP, ICMP_GetPacket);
33 * \fn void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer)
34 * \brief Handles a packet from the IP Layer
36 void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer)
38 tICMPHeader *hdr = Buffer;
40 Log("[ICMP ] hdr->Type = %i", hdr->Type);
41 Log("[ICMP ] hdr->Code = %i", hdr->Code);
42 Log("[ICMP ] hdr->Checksum = 0x%x", ntohs(hdr->Checksum));
43 Log("[ICMP ] hdr->ID = 0x%x", ntohs(hdr->ID));
44 Log("[ICMP ] hdr->Sequence = 0x%x", ntohs(hdr->Sequence));
50 Warning("[ICMP ] Code == %i for ICMP Echo Reply, should be 0", hdr->Code);
53 if(hdr->ID != ~hdr->Sequence) {
54 Warning("[ICMP ] ID and Sequence values do not match");
57 gICMP_PingSlots[hdr->ID].bArrived = 1;
64 * \brief Sends ICMP Echo and waits for the reply
65 * \note Times out after \a Interface->TimeoutDelay has elapsed
67 int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
70 char buf[32] = "\x8\0\0\0\0\0\0\0Acess2 I"
72 tICMPHeader *hdr = (void*)buf;
77 for(i=0;i<PING_SLOTS;i++)
79 if(gICMP_PingSlots[i].Interface == NULL) break;
81 if(gICMP_PingSlots[i].Interface == NULL) break;
84 gICMP_PingSlots[i].Interface = Interface;
85 gICMP_PingSlots[i].bArrived = 0;
88 hdr->Checksum = htons( IPv4_Checksum(hdr, sizeof(buf)) );
89 IPv4_SendPacket(Interface, Addr, 1, i, 32, buf);