Changeset 10983 in vbox for trunk/src/VBox/Devices/Network/testcase
- Timestamp:
- Jul 30, 2008 1:34:08 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 33858
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/testcase/tstIntNet-1.cpp
r10979 r10983 200 200 201 201 /** 202 * Internt protocol checksumming203 * This is great fun because of the pseudo header.204 */205 static uint16_t tstIntNet1InetCheckSum(void const *pvBuf, size_t cbBuf, uint32_t u32Src, uint32_t u32Dst, uint8_t u8Proto)206 {207 /*208 * Construct the pseudo header and sum it.209 */210 struct pseudo_header211 {212 uint32_t u32Src;213 uint32_t u32Dst;214 uint8_t u8Zero;215 uint8_t u8Proto;216 uint16_t u16Len;217 } s =218 {219 RT_H2BE_U32(u32Src),220 RT_H2BE_U32(u32Dst),221 0,222 u8Proto,223 RT_H2BE_U16((uint16_t)cbBuf)224 };225 const uint16_t *pu16 = (const uint16_t *)&s;226 int32_t iSum = *pu16++;227 iSum += *pu16++;228 iSum += *pu16++;229 iSum += *pu16++;230 iSum += *pu16++;231 iSum += *pu16++;232 AssertCompileSize(s, 12);233 234 /*235 * Continue with protocol header and data.236 */237 pu16 = (const uint16_t *)pvBuf;238 while (cbBuf > 1)239 {240 iSum += *pu16++;241 cbBuf -= 2;242 }243 244 /* deal with odd size */245 if (cbBuf)246 {247 RTUINT16U u16;248 u16.u = 0;249 u16.au8[0] = *(uint8_t const *)pu16;250 iSum += u16.u;251 }252 253 /* 16-bit one complement fun */254 iSum = (iSum >> 16) + (iSum & 0xffff); /* hi + low words */255 iSum += iSum >> 16; /* carry */256 return (uint16_t)~iSum;257 }258 259 260 /**261 * IP checksumming262 */263 static uint16_t tstIntNet1IpCheckSum(void const *pvBuf, size_t cbBuf)264 {265 const uint16_t *pu16 = (const uint16_t *)pvBuf;266 int32_t iSum = 0;267 while (cbBuf > 1)268 {269 iSum += *pu16++;270 cbBuf -= 2;271 }272 273 /* deal with odd size */274 if (cbBuf)275 {276 RTUINT16U u16;277 u16.u = 0;278 u16.au8[0] = *(uint8_t const *)pu16;279 iSum += u16.u;280 }281 282 /* 16-bit one complement fun */283 iSum = (iSum >> 16) + (iSum & 0xffff); /* hi + low words */284 iSum += iSum >> 16; /* carry */285 return (uint16_t)~iSum;286 }287 288 289 /**290 202 * Does the transmit test. 291 203 * … … 371 283 pIpHdr->ip_src.u = 0; 372 284 pIpHdr->ip_dst.u = UINT32_C(0xffffffff); /* broadcast */ 373 pIpHdr->ip_sum = tstIntNet1IpCheckSum(pIpHdr, sizeof(*pIpHdr));285 pIpHdr->ip_sum = RTNetIPv4HdrChecksum(pIpHdr); 374 286 375 287 /* calc the UDP checksum. */ 376 pUdpHdr->uh_sum = tstIntNet1InetCheckSum(pUdpHdr, 377 RT_BE2H_U16(pUdpHdr->uh_ulen), 378 RT_BE2H_U32(pIpHdr->ip_src.u), 379 RT_BE2H_U32(pIpHdr->ip_dst.u), 380 pIpHdr->ip_p); 288 pUdpHdr->uh_sum = RTNetIPv4UDPChecksum(pIpHdr, pUdpHdr, pUdpHdr + 1); 381 289 382 290 /* Ethernet */
Note:
See TracChangeset
for help on using the changeset viewer.