Changes in uspace/srv/net/udp/pdu.c [69a93df7:695b6ff] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/pdu.c
r69a93df7 r695b6ff 40 40 #include <mem.h> 41 41 #include <stdlib.h> 42 42 #include <inet/addr.h> 43 #include <net/socket_codes.h> 43 44 #include "msg.h" 44 45 #include "pdu.h" … … 84 85 } 85 86 86 static void udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr) 87 { 88 phdr->src_addr = host2uint32_t_be(pdu->src.ipv4); 89 phdr->dest_addr = host2uint32_t_be(pdu->dest.ipv4); 90 phdr->zero = 0; 91 phdr->protocol = IP_PROTO_UDP; 92 phdr->udp_length = host2uint16_t_be(pdu->data_size); 87 static uint16_t udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr, 88 udp_phdr6_t *phdr6) 89 { 90 addr32_t src_v4; 91 addr128_t src_v6; 92 uint16_t src_af = inet_addr_get(&pdu->src, &src_v4, &src_v6); 93 94 addr32_t dest_v4; 95 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: 102 phdr->src_addr = host2uint32_t_be(src_v4); 103 phdr->dest_addr = host2uint32_t_be(dest_v4); 104 phdr->zero = 0; 105 phdr->protocol = IP_PROTO_UDP; 106 phdr->udp_length = host2uint16_t_be(pdu->data_size); 107 break; 108 case AF_INET6: 109 host2addr128_t_be(src_v6, phdr6->src_addr); 110 host2addr128_t_be(dest_v6, phdr6->dest_addr); 111 phdr6->udp_length = host2uint32_t_be(pdu->data_size); 112 memset(phdr6->zeroes, 0, 3); 113 phdr6->next = IP_PROTO_UDP; 114 break; 115 default: 116 assert(false); 117 } 118 119 return src_af; 93 120 } 94 121 … … 107 134 { 108 135 uint16_t cs_phdr; 109 uint16_t cs_all;110 136 udp_phdr_t phdr; 111 112 udp_phdr_setup(pdu, &phdr); 113 cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *)&phdr, 114 sizeof(udp_phdr_t)); 115 cs_all = udp_checksum_calc(cs_phdr, pdu->data, pdu->data_size); 116 117 return cs_all; 137 udp_phdr6_t phdr6; 138 139 uint16_t af = udp_phdr_setup(pdu, &phdr, &phdr6); 140 switch (af) { 141 case AF_INET: 142 cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *) &phdr, 143 sizeof(udp_phdr_t)); 144 break; 145 case AF_INET6: 146 cs_phdr = udp_checksum_calc(UDP_CHECKSUM_INIT, (void *) &phdr6, 147 sizeof(udp_phdr6_t)); 148 break; 149 default: 150 assert(false); 151 } 152 153 return udp_checksum_calc(cs_phdr, pdu->data, pdu->data_size); 118 154 } 119 155 … … 179 215 return ENOMEM; 180 216 217 npdu->iplink = sp->iplink; 181 218 npdu->src = sp->local.addr; 182 219 npdu->dest = sp->foreign.addr;
Note:
See TracChangeset
for help on using the changeset viewer.