Changeset 2092

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

Fix UDP warnings.

Files:
1 modified

Legend:

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

    r2088 r2092  
    55#include <net/channels.h> 
    66#include <net/ipv4.h> 
     7#include <net/udp.h> 
    78 
    89#include "checksum.h" 
     10#include "ipv4.h" 
    911 
    1012static struct SocketOps udpSocketOps; 
     
    7274} 
    7375 
    74 ulong WrapSum(ulong sum) 
    75 { 
    76         sum=~sum & 0xFFFF; 
    77         return HostToNetShort(sum); 
    78 } 
    79  
    80 ulong UdpCheckSum() 
    81 { 
    82         return 0; 
    83 } 
    84  
    8576int UdpSocketSendTo(Socket* socket, const void* buffer, unsigned long length, int flags, struct SockAddr* dest) 
    8677{ 
     
    10192        chanBuff = ChanSendBufferAlloc(socket->channel, &data); 
    10293 
    103         printf("chanBuff = %#X, data = %#X\n", chanBuff, data); 
    104  
    10594        if (!chanBuff) 
    10695                return -1; 
     
    117106         
    118107        memcpy(data + sizeof(struct IpHeader) + sizeof(struct UdpHeader), buffer, length); 
    119          
    120 /*      udpHeader->checkSum = WrapSum(IpCheckSum((unsigned char*)udpHeader, sizeof(struct UdpHeader), 
    121                                                 IpCheckSum(start+sizeof(struct IpHeader)+sizeof(struct UdpHeader), length, 
    122                                                         IpCheckSum((unsigned char*)&ipHeader->sourceAddr, 8, 
    123                                                         PROTOCOL_RAW_UDP + 
    124                                                         HostToNetShort(udpHeader->length))))); */ 
    125  
    126         ret = ChanBufferSend(socket->channel, chanBuff, totalLength); 
     108         
     109        ret = ChanBufferSend(socket->channel, chanBuff, totalLength); 
    127110         
    128111        return ret; 
    129112} 
    130113 
    131 int UdpCalcChecksum(struct IpHeader* ipHeader, struct UdpHeader* udpHeader, int read) 
     114ushort UdpCalcChecksum(struct IpHeader* ipHeader, struct UdpHeader* udpHeader, int read) 
    132115{ 
    133         ushort sum = udpHeader->checkSum; 
     116        ushort oldSum = udpHeader->checkSum, sum; 
     117        int protoLength = NetToHostShort(ipHeader->totalLength) - sizeof(struct IpHeader); 
    134118 
    135119        udpHeader->checkSum = 0; 
     120         
     121        sum = TcpUdpHeaderSum(ipHeader->sourceAddr, ipHeader->destAddr, protoLength, IP_PROTOCOL_UDP); 
     122        sum = ~IpPartialSum(udpHeader, protoLength, sum); 
    136123 
    137         udpHeader->checkSum = sum; 
     124        udpHeader->checkSum = oldSum; 
     125 
     126        return sum; 
    138127} 
    139128 
     
    160149        ipHeader = (struct IpHeader*)buf; 
    161150        udpHeader = (struct UdpHeader*)(buf + sizeof(struct IpHeader)); 
    162         if (NetToHostShort(udpHeader->checkSum) != UdpCalcChecksum(ipHeader, udpHeader, read)) 
     151        if (udpHeader->checkSum != UdpCalcChecksum(ipHeader, udpHeader, read)) 
    163152                goto again; 
     153 
     154        /* TODO: Current buffer. Partial recv */ 
    164155 
    165156        dataByteCnt = read - sizeof(struct UdpHeader) - sizeof(struct IpHeader);