Changeset 02a09ed in mainline for uspace/srv/net/tcp/pdu.c
- Timestamp:
- 2013-06-28T20:20:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1d24ad3
- Parents:
- edf0d27
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/tcp/pdu.c
redf0d27 r02a09ed 40 40 #include <mem.h> 41 41 #include <stdlib.h> 42 #include <net/socket_codes.h> 42 43 #include "pdu.h" 43 44 #include "segment.h" … … 144 145 } 145 146 146 static void tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr) 147 { 148 // FIXME: Check for correctness 149 150 uint32_t src_addr; 151 inet_addr_pack(&pdu->src_addr, &src_addr); 152 153 uint32_t dest_addr; 154 inet_addr_pack(&pdu->dest_addr, &dest_addr); 155 156 phdr->src_addr = host2uint32_t_be(src_addr); 157 phdr->dest_addr = host2uint32_t_be(dest_addr); 158 phdr->zero = 0; 159 phdr->protocol = 6; /* XXX Magic number */ 160 phdr->tcp_length = host2uint16_t_be(pdu->header_size + pdu->text_size); 147 static uint16_t tcp_phdr_setup(tcp_pdu_t *pdu, tcp_phdr_t *phdr) 148 { 149 addr32_t src_v4; 150 addr128_t src_v6; 151 uint16_t src_af = inet_addr_get(&pdu->src, &src_v4, &src_v6); 152 153 addr32_t dest_v4; 154 addr128_t dest_v6; 155 uint16_t dest_af = inet_addr_get(&pdu->dest, &dest_v4, &dest_v6); 156 157 assert(src_af == dest_af); 158 159 switch (src_af) { 160 case AF_INET: 161 phdr->src = host2uint32_t_be(src_v4); 162 phdr->dest = host2uint32_t_be(dest_v4); 163 phdr->zero = 0; 164 phdr->protocol = IP_PROTO_TCP; 165 phdr->tcp_length = 166 host2uint16_t_be(pdu->header_size + pdu->text_size); 167 break; 168 case AF_INET6: 169 // FIXME TODO 170 assert(false); 171 default: 172 assert(false); 173 } 174 175 return src_af; 161 176 } 162 177 … … 243 258 uint16_t cs_phdr; 244 259 uint16_t cs_headers; 245 uint16_t cs_all;246 260 tcp_phdr_t phdr; 247 248 tcp_phdr_setup(pdu, &phdr); 249 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *)&phdr, 250 sizeof(tcp_phdr_t)); 261 262 uint16_t af = tcp_phdr_setup(pdu, &phdr); 263 switch (af) { 264 case AF_INET: 265 cs_phdr = tcp_checksum_calc(TCP_CHECKSUM_INIT, (void *) &phdr, 266 sizeof(tcp_phdr_t)); 267 break; 268 case AF_INET6: 269 // FIXME TODO 270 assert(false); 271 default: 272 assert(false); 273 } 274 251 275 cs_headers = tcp_checksum_calc(cs_phdr, pdu->header, pdu->header_size); 252 cs_all = tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size); 253 254 return cs_all; 276 return tcp_checksum_calc(cs_headers, pdu->text, pdu->text_size); 255 277 } 256 278 … … 279 301 280 302 sp->local.port = uint16_t_be2host(hdr->dest_port); 281 sp->local.addr = pdu->dest _addr;303 sp->local.addr = pdu->dest; 282 304 sp->foreign.port = uint16_t_be2host(hdr->src_port); 283 sp->foreign.addr = pdu->src _addr;305 sp->foreign.addr = pdu->src; 284 306 285 307 *seg = nseg; … … 298 320 return ENOMEM; 299 321 300 npdu->src _addr= sp->local.addr;301 npdu->dest _addr= sp->foreign.addr;322 npdu->src = sp->local.addr; 323 npdu->dest = sp->foreign.addr; 302 324 tcp_header_encode(sp, seg, &npdu->header, &npdu->header_size); 303 325
Note:
See TracChangeset
for help on using the changeset viewer.