Fixed IPv4 checksum (network byte order, dimwit)
[tpg/acess2.git] / Modules / IPStack / ipv4.c
index 672b4ec..31d6f02 100644 (file)
@@ -69,9 +69,9 @@ int IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int
        tIPv4Header     *hdr = (void*)buf;
         int    ret;
        
-       // TODO: OUTPUT Firewall rule go here
+       // OUTPUT Firewall rule go here
        ret = IPTablesV4_TestChain("OUTPUT",
-               &Iface->IP4.Address, &Address,
+               (tIPv4*)Iface->Address, &Address,
                Protocol, 0,
                Length, Data);
        if(ret != 0) {
@@ -95,7 +95,7 @@ int IPv4_SendPacket(tInterface *Iface, tIPv4 Address, int Protocol, int ID, int
        hdr->TTL = DEFAULT_TTL;
        hdr->Protocol = Protocol;
        hdr->HeaderChecksum = 0;        // Will be set later
-       hdr->Source = Iface->IP4.Address;
+       hdr->Source = *(tIPv4*)Iface->Address;
        hdr->Destination = Address;
        hdr->HeaderChecksum = IPv4_Checksum(hdr, sizeof(tIPv4Header));
        
@@ -236,15 +236,15 @@ tInterface *IPv4_GetInterface(tAdapter *Adapter, tIPv4 Address, int Broadcast)
        {
                if( iface->Adapter != Adapter ) continue;
                if( iface->Type != 4 )  continue;
-               if( IP4_EQU(Address, iface->IP4.Address) )
+               if( IP4_EQU(Address, *(tIPv4*)iface->Address) )
                        return iface;
                
                if( !Broadcast )        continue;
                
-               this = ntohl( iface->IP4.Address.L );
+               this = ntohl( ((tIPv4*)iface->Address)->L );
                
                // Check for broadcast
-               netmask = IPv4_Netmask(iface->IP4.SubnetBits);
+               netmask = IPv4_Netmask(iface->SubnetBits);
                
                if( (addr & netmask) == (this & netmask)
                 && (addr & ~netmask) == (0xFFFFFFFF & ~netmask) )
@@ -284,9 +284,10 @@ Uint16 IPv4_Checksum(const void *Buf, int Size)
        Size = (Size + 1) >> 1; // 16-bit word count
        for(i = 0; i < Size; i++ )
        {
-               if((int)sum + arr[i] > 0xFFFF)
+               Uint16  val = ntohs(arr[i]);
+               if((int)sum + val > 0xFFFF)
                        sum ++; // Simulate 1's complement
-               sum += arr[i];
+               sum += val;
        }
        return ~sum ;
 }

UCC git Repository :: git.ucc.asn.au