Changeset 2092
- Timestamp:
- 05/27/10 12:20:14 (21 months ago)
- Files:
-
- 1 modified
-
Whitix/branches/netchannel/user/sdk/network/udp.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/netchannel/user/sdk/network/udp.c
r2088 r2092 5 5 #include <net/channels.h> 6 6 #include <net/ipv4.h> 7 #include <net/udp.h> 7 8 8 9 #include "checksum.h" 10 #include "ipv4.h" 9 11 10 12 static struct SocketOps udpSocketOps; … … 72 74 } 73 75 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 85 76 int UdpSocketSendTo(Socket* socket, const void* buffer, unsigned long length, int flags, struct SockAddr* dest) 86 77 { … … 101 92 chanBuff = ChanSendBufferAlloc(socket->channel, &data); 102 93 103 printf("chanBuff = %#X, data = %#X\n", chanBuff, data);104 105 94 if (!chanBuff) 106 95 return -1; … … 117 106 118 107 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); 127 110 128 111 return ret; 129 112 } 130 113 131 int UdpCalcChecksum(struct IpHeader* ipHeader, struct UdpHeader* udpHeader, int read)114 ushort UdpCalcChecksum(struct IpHeader* ipHeader, struct UdpHeader* udpHeader, int read) 132 115 { 133 ushort sum = udpHeader->checkSum; 116 ushort oldSum = udpHeader->checkSum, sum; 117 int protoLength = NetToHostShort(ipHeader->totalLength) - sizeof(struct IpHeader); 134 118 135 119 udpHeader->checkSum = 0; 120 121 sum = TcpUdpHeaderSum(ipHeader->sourceAddr, ipHeader->destAddr, protoLength, IP_PROTOCOL_UDP); 122 sum = ~IpPartialSum(udpHeader, protoLength, sum); 136 123 137 udpHeader->checkSum = sum; 124 udpHeader->checkSum = oldSum; 125 126 return sum; 138 127 } 139 128 … … 160 149 ipHeader = (struct IpHeader*)buf; 161 150 udpHeader = (struct UdpHeader*)(buf + sizeof(struct IpHeader)); 162 if ( NetToHostShort(udpHeader->checkSum)!= UdpCalcChecksum(ipHeader, udpHeader, read))151 if (udpHeader->checkSum != UdpCalcChecksum(ipHeader, udpHeader, read)) 163 152 goto again; 153 154 /* TODO: Current buffer. Partial recv */ 164 155 165 156 dataByteCnt = read - sizeof(struct UdpHeader) - sizeof(struct IpHeader);
