Changeset 0ac2158 in mainline for uspace/srv/net/tl/tcp/pdu.c
- Timestamp:
- 2011-12-08T23:29:06Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d9e14fa4
- Parents:
- 5f9ecd3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tl/tcp/pdu.c
r5f9ecd3 r0ac2158 48 48 #define TCP_CHECKSUM_INIT 0xffff 49 49 50 /** One's complement addition. 51 * 52 * Result is a + b + carry. 53 */ 54 static uint16_t tcp_ocadd16(uint16_t a, uint16_t b) 55 { 56 uint32_t s; 57 58 s = (uint32_t)a + (uint32_t)b; 59 return (s & 0xffff) + (s >> 16); 60 } 61 50 62 static uint16_t tcp_checksum_calc(uint16_t ivalue, void *data, size_t size) 51 63 { 52 64 uint16_t sum; 65 uint16_t w; 53 66 size_t words, i; 54 67 uint8_t *bdata; … … 59 72 60 73 for (i = 0; i < words; i++) { 61 sum += ~(((uint16_t)bdata[2*i] << 8) + bdata[2*i + 1]); 74 w = ((uint16_t)bdata[2*i] << 8) | bdata[2*i + 1]; 75 sum = tcp_ocadd16(sum, w); 62 76 } 63 77 64 78 if (size % 2 != 0) { 65 sum += ~((uint16_t)bdata[2*words] << 8); 79 w = ((uint16_t)bdata[2*words] << 8); 80 sum = tcp_ocadd16(sum, w); 66 81 } 67 82 … … 237 252 238 253 hdr = (tcp_header_t *)pdu->header; 239 hdr->checksum = host2uint16_t_ le(checksum);254 hdr->checksum = host2uint16_t_be(checksum); 240 255 } 241 256
Note:
See TracChangeset
for help on using the changeset viewer.