Changes in uspace/srv/net/udp/pdu.c [12df1f1:8d48c7e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/pdu.c
r12df1f1 r8d48c7e 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2015 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 41 41 #include <stdlib.h> 42 42 #include <inet/addr.h> 43 #include <net/socket_codes.h>44 43 #include "msg.h" 45 44 #include "pdu.h" … … 85 84 } 86 85 87 static uint16_t udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr,86 static ip_ver_t udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr, 88 87 udp_phdr6_t *phdr6) 89 88 { 90 89 addr32_t src_v4; 91 90 addr128_t src_v6; 92 uint16_t src_af= inet_addr_get(&pdu->src, &src_v4, &src_v6);93 91 ip_ver_t src_ver = inet_addr_get(&pdu->src, &src_v4, &src_v6); 92 94 93 addr32_t dest_v4; 95 94 addr128_t dest_v6; 96 uint16_t dest_af= inet_addr_get(&pdu->dest, &dest_v4, &dest_v6);97 98 assert(src_ af == dest_af);99 100 switch (src_ af) {101 case AF_INET:95 ip_ver_t dest_ver = inet_addr_get(&pdu->dest, &dest_v4, &dest_v6); 96 97 assert(src_ver == dest_ver); 98 99 switch (src_ver) { 100 case ip_v4: 102 101 phdr->src_addr = host2uint32_t_be(src_v4); 103 102 phdr->dest_addr = host2uint32_t_be(dest_v4); … … 106 105 phdr->udp_length = host2uint16_t_be(pdu->data_size); 107 106 break; 108 case AF_INET6:107 case ip_v6: 109 108 host2addr128_t_be(src_v6, phdr6->src_addr); 110 109 host2addr128_t_be(dest_v6, phdr6->dest_addr); … … 116 115 assert(false); 117 116 } 118 119 return src_ af;117 118 return src_ver; 120 119 } 121 120 … … 136 135 udp_phdr_t phdr; 137 136 udp_phdr6_t phdr6; 138 139 uint16_t af= udp_phdr_setup(pdu, &phdr, &phdr6);140 switch ( af) {141 case AF_INET:137 138 ip_ver_t ver = udp_phdr_setup(pdu, &phdr, &phdr6); 139 switch (ver) { 140 case ip_v4: 142 141 cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *) &phdr, 143 142 sizeof(udp_phdr_t)); 144 143 break; 145 case AF_INET6:144 case ip_v6: 146 145 cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *) &phdr6, 147 146 sizeof(udp_phdr6_t)); … … 150 149 assert(false); 151 150 } 152 151 153 152 return udp_checksum_calc(cs_phdr, pdu->data, pdu->data_size); 154 153 } … … 163 162 164 163 /** Decode incoming PDU */ 165 int udp_pdu_decode(udp_pdu_t *pdu, udp_sockpair_t *sp, udp_msg_t **msg)164 int udp_pdu_decode(udp_pdu_t *pdu, inet_ep2_t *epp, udp_msg_t **msg) 166 165 { 167 166 udp_msg_t *nmsg; … … 180 179 hdr = (udp_header_t *)pdu->data; 181 180 182 sp->foreign.port = uint16_t_be2host(hdr->src_port); 183 sp->foreign.addr = pdu->src; 184 sp->local.port = uint16_t_be2host(hdr->dest_port); 185 sp->local.addr = pdu->dest; 181 epp->local_link = pdu->iplink; 182 epp->remote.port = uint16_t_be2host(hdr->src_port); 183 epp->remote.addr = pdu->src; 184 epp->local.port = uint16_t_be2host(hdr->dest_port); 185 epp->local.addr = pdu->dest; 186 186 187 187 length = uint16_t_be2host(hdr->length); … … 197 197 return ENOMEM; 198 198 199 nmsg->data = text;200 199 nmsg->data_size = length - sizeof(udp_header_t); 200 nmsg->data = malloc(nmsg->data_size); 201 if (nmsg->data == NULL) 202 return ENOMEM; 203 204 memcpy(nmsg->data, text, nmsg->data_size); 201 205 202 206 *msg = nmsg; … … 205 209 206 210 /** Encode outgoing PDU */ 207 int udp_pdu_encode( udp_sockpair_t *sp, udp_msg_t *msg, udp_pdu_t **pdu)211 int udp_pdu_encode(inet_ep2_t *epp, udp_msg_t *msg, udp_pdu_t **pdu) 208 212 { 209 213 udp_pdu_t *npdu; … … 215 219 return ENOMEM; 216 220 217 npdu->src = sp->local.addr; 218 npdu->dest = sp->foreign.addr; 221 npdu->iplink = epp->local_link; 222 npdu->src = epp->local.addr; 223 npdu->dest = epp->remote.addr; 219 224 220 225 npdu->data_size = sizeof(udp_header_t) + msg->data_size; … … 226 231 227 232 hdr = (udp_header_t *)npdu->data; 228 hdr->src_port = host2uint16_t_be( sp->local.port);229 hdr->dest_port = host2uint16_t_be( sp->foreign.port);233 hdr->src_port = host2uint16_t_be(epp->local.port); 234 hdr->dest_port = host2uint16_t_be(epp->remote.port); 230 235 hdr->length = host2uint16_t_be(npdu->data_size); 231 236 hdr->checksum = 0;
Note:
See TracChangeset
for help on using the changeset viewer.