X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Modules%2FIPStack%2Fipv4.c;h=04b8f4b77c93e7af48943c02956eebcceabe9b61;hb=9e4f0db5f7ccc535cb72d6ab2f96e201b050ef20;hp=6c387cc173e0e6b48a78854e335af096acaaa559;hpb=ffd7eba4e4181dea44c3687e411f1915630abedb;p=tpg%2Facess2.git diff --git a/Modules/IPStack/ipv4.c b/Modules/IPStack/ipv4.c index 6c387cc1..04b8f4b7 100644 --- a/Modules/IPStack/ipv4.c +++ b/Modules/IPStack/ipv4.c @@ -21,7 +21,7 @@ extern tMacAddr ARP_Resolve4(tInterface *Interface, tIPv4 Address); void IPv4_int_GetPacket(tAdapter *Interface, tMacAddr From, int Length, void *Buffer); tInterface *IPv4_GetInterface(tAdapter *Adapter, tIPv4 Address, int Broadcast); Uint32 IPv4_Netmask(int FixedBits); -Uint16 IPv4_Checksum(const void *Buf, int Size); +Uint16 IPv4_Checksum(const Uint16 *Buf, int WordCount); int IPv4_Ping(tInterface *Iface, tIPv4 Addr); // === GLOBALS === @@ -105,7 +105,7 @@ int IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int hdr->HeaderChecksum = 0; // Will be set later hdr->Source = *(tIPv4*)Iface->Address; hdr->Destination = Address; - hdr->HeaderChecksum = htons(IPv4_Checksum(hdr, sizeof(tIPv4Header))); + hdr->HeaderChecksum = htons(IPv4_Checksum((Uint16*)hdr, sizeof(tIPv4Header)/2)); Log_Log("IPv4", "Sending packet to %i.%i.%i.%i", Address.B[0], Address.B[1], Address.B[2], Address.B[3]); @@ -154,7 +154,7 @@ void IPv4_int_GetPacket(tAdapter *Adapter, tMacAddr From, int Length, void *Buff Uint16 hdrVal, compVal; hdrVal = ntohs(hdr->HeaderChecksum); hdr->HeaderChecksum = 0; - compVal = IPv4_Checksum(hdr, hdr->HeaderLength * 4); + compVal = IPv4_Checksum((Uint16*)hdr, (hdr->HeaderLength * 4) / 2); if(hdrVal != compVal) { Log_Log("IPv4", "Header checksum fails (%04x != %04x)", hdrVal, compVal); return ; @@ -311,21 +311,17 @@ Uint32 IPv4_Netmask(int FixedBits) * * One's complement sum of all 16-bit words (bitwise inverted) */ -Uint16 IPv4_Checksum(const void *Buf, int Size) +Uint16 IPv4_Checksum(const Uint16 *Buf, int WordCount) { Uint32 sum = 0; - const Uint16 *arr = Buf; int i; // Sum all whole words - for(i = 0; i < Size/2; i++ ) + for(i = 0; i < WordCount; i++ ) { - Uint16 val = ntohs(arr[i]); + Uint16 val = ntohs(Buf[i]); sum += val; } - // Add the tail word -// if( i*2 != Size ) -// sum += arr[i]&0xFF; // Apply one's complement while (sum >> 16)