Changes in uspace/srv/net/udp/pdu.c [1d24ad3:69a93df7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/udp/pdu.c
r1d24ad3 r69a93df7 40 40 #include <mem.h> 41 41 #include <stdlib.h> 42 #include <inet/addr.h> 43 #include <net/socket_codes.h> 42 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, 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->zero, 0, 3); 113 phdr6->next = IP_PROTO_UDP; 114 break; 115 default: 116 assert(false); 117 } 118 119 return src_af; 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); 120 93 } 121 94 … … 134 107 { 135 108 uint16_t cs_phdr; 109 uint16_t cs_all; 136 110 udp_phdr_t phdr; 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); 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; 154 118 } 155 119
Note:
See TracChangeset
for help on using the changeset viewer.