X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FIPStack%2Ficmp.c;h=66f0f96a6c3b912b17436bb047d161a19d54be74;hb=HEAD;hp=3f82f878121621feb2bceb0ee95338cbbbca0e1c;hpb=25f19babe7a0ab75d04ff7e6f98f7bcb65fb8941;p=tpg%2Facess2.git diff --git a/Modules/IPStack/icmp.c b/Modules/IPStack/icmp.c deleted file mode 100644 index 3f82f878..00000000 --- a/Modules/IPStack/icmp.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Acess2 IP Stack - * - ICMP Handling - */ -#include "ipstack.h" -#include "ipv4.h" -#include "icmp.h" - -// === CONSTANTS === -#define PING_SLOTS 64 - -// === PROTOTYPES === -void ICMP_Initialise(); -void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer); - -// === GLOBALS === -struct { - tInterface *Interface; - int bArrived; -} gICMP_PingSlots[PING_SLOTS]; - -// === CODE === -/** - * \fn void ICMP_Initialise() - * \brief Initialise the ICMP Layer - */ -void ICMP_Initialise() -{ - IPv4_RegisterCallback(IP4PROT_ICMP, ICMP_GetPacket); -} - -/** - * \fn void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer) - * \brief Handles a packet from the IP Layer - */ -void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buffer) -{ - tICMPHeader *hdr = Buffer; - - Log("[ICMP ] hdr->Type = %i", hdr->Type); - Log("[ICMP ] hdr->Code = %i", hdr->Code); - Log("[ICMP ] hdr->Checksum = 0x%x", ntohs(hdr->Checksum)); - Log("[ICMP ] hdr->ID = 0x%x", ntohs(hdr->ID)); - Log("[ICMP ] hdr->Sequence = 0x%x", ntohs(hdr->Sequence)); - - switch(hdr->Type) - { - case ICMP_ECHOREPLY: - if(hdr->Code != 0) { - Warning("[ICMP ] Code == %i for ICMP Echo Reply, should be 0", hdr->Code); - return ; - } - if(hdr->ID != ~hdr->Sequence) { - Warning("[ICMP ] ID and Sequence values do not match"); - return ; - } - gICMP_PingSlots[hdr->ID].bArrived = 1; - break; - } - -} - -/** - * \brief Sends ICMP Echo and waits for the reply - * \note Times out after \a Interface->TimeoutDelay has elapsed - */ -int ICMP_Ping(tInterface *Interface, tIPv4 Addr) -{ - //Sint64 ts; - char buf[32] = "\x8\0\0\0\0\0\0\0Acess2 I" - "P/TCP Stack 1.0\0"; - tICMPHeader *hdr = (void*)buf; - int i; - - for(;;) - { - for(i=0;iID = i; - hdr->Sequence = ~i; - hdr->Checksum = htons( IPv4_Checksum(hdr, sizeof(buf)) ); - IPv4_SendPacket(Interface, Addr, 1, i, 32, buf); - - return -1; -}