Changeset 2089

Show
Ignore:
Timestamp:
05/27/10 12:19:36 (21 months ago)
Author:
mwhitworth
Message:

Add IpPartialSum.

Files:
1 modified

Legend:

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

    r2088 r2089  
    1010        ushort length; 
    1111}__attribute__((packed)); 
     12 
     13static 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} 
    1233 
    1334static inline ushort TcpUdpHeaderSum(ulong sourceAddr, ulong destAddr, ushort len, uchar proto)