Show
Ignore:
Timestamp:
05/26/10 12:23:09 (2 years ago)
Author:
mwhitworth
Message:

Update to actually include all network stack progress so far.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/netchannel/user/sdk/network/udp.c

    r2084 r2088  
    55#include <net/channels.h> 
    66#include <net/ipv4.h> 
     7 
     8#include "checksum.h" 
    79 
    810static struct SocketOps udpSocketOps; 
     
    127129} 
    128130 
     131int UdpCalcChecksum(struct IpHeader* ipHeader, struct UdpHeader* udpHeader, int read) 
     132{ 
     133        ushort sum = udpHeader->checkSum; 
     134 
     135        udpHeader->checkSum = 0; 
     136 
     137        udpHeader->checkSum = sum; 
     138} 
     139 
    129140int UdpSocketRecvFrom(Socket* socket, void* buffer, unsigned long length, int flags, 
    130141        struct SockAddr* dest) 
     
    134145        char* buf; 
    135146        int dataByteCnt; 
     147        struct IpHeader* ipHeader; 
     148        struct UdpHeader* udpHeader; 
    136149 
     150again: 
    137151        read = ChanBufferRecv(socket->channel, &chanBuff, &buf, 2000); 
    138152 
     
    142156                return read; 
    143157        } 
     158 
     159        /* Verify checksum */ 
     160        ipHeader = (struct IpHeader*)buf; 
     161        udpHeader = (struct UdpHeader*)(buf + sizeof(struct IpHeader)); 
     162        if (NetToHostShort(udpHeader->checkSum) != UdpCalcChecksum(ipHeader, udpHeader, read)) 
     163                goto again; 
    144164 
    145165        dataByteCnt = read - sizeof(struct UdpHeader) - sizeof(struct IpHeader);