Show
Ignore:
Timestamp:
06/03/10 22:43:33 (2 years ago)
Author:
mwhitworth
Message:

Add to network stack.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/netchannel/user/sdk/network/checksum.h

    r2089 r2099  
    1010        ushort length; 
    1111}__attribute__((packed)); 
    12  
    13 static inline ushort IpPartialSum(void* _data, ulong bytes, ushort _sum) 
    14 { 
    15         uchar* data = (uchar*)_data; 
    16         ulong sum = _sum; 
    17  
    18         while (bytes > 1) 
    19         { 
    20                 sum += (((ushort)*(data+1) << 8) | *data); 
    21                 data += 2; 
    22                 bytes -= 2; 
    23         } 
    24  
    25         if (bytes) 
    26                 sum += *data; 
    27  
    28         while (sum >> 16) 
    29                 sum = (ushort)sum + (sum >> 16); 
    30  
    31         return (ushort)sum; 
    32 } 
    33  
    34 static inline ushort TcpUdpHeaderSum(ulong sourceAddr, ulong destAddr, ushort len, uchar proto) 
    35 { 
    36         struct IpPsuedoHdr hdr; 
    37  
    38         hdr.sourceIp = sourceAddr; 
    39         hdr.destIp = destAddr; 
    40         hdr.zero = 0; 
    41         hdr.length = HostToNetShort(len); 
    42         hdr.proto = proto; 
    43  
    44         return IpPartialSum(&hdr, sizeof(struct IpPsuedoHdr), 0); 
    45 } 
    46  
    4712#endif