Changes in uspace/lib/net/tl/tl_common.c [2fa0ad9:7c8267b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/tl/tl_common.c
r2fa0ad9 r7c8267b 58 58 DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t); 59 59 60 int 61 tl_get_address_port(const struct sockaddr *addr, int addrlen, uint16_t *port) 62 { 63 const struct sockaddr_in *address_in; 64 const struct sockaddr_in6 *address_in6; 65 66 if ((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))) 67 return EINVAL; 68 69 switch (addr->sa_family) { 70 case AF_INET: 71 if (addrlen != sizeof(struct sockaddr_in)) 72 return EINVAL; 73 74 address_in = (struct sockaddr_in *) addr; 75 *port = ntohs(address_in->sin_port); 76 break; 77 case AF_INET6: 78 if (addrlen != sizeof(struct sockaddr_in6)) 60 int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port){ 61 const struct sockaddr_in * address_in; 62 const struct sockaddr_in6 * address_in6; 63 64 if((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))){ 65 return EINVAL; 66 } 67 switch(addr->sa_family){ 68 case AF_INET: 69 if(addrlen != sizeof(struct sockaddr_in)){ 79 70 return EINVAL; 80 81 address_in6 = (struct sockaddr_in6 *) addr; 82 *port = ntohs(address_in6->sin6_port); 83 break; 84 default: 85 return EAFNOSUPPORT; 86 } 87 71 } 72 address_in = (struct sockaddr_in *) addr; 73 *port = ntohs(address_in->sin_port); 74 break; 75 case AF_INET6: 76 if(addrlen != sizeof(struct sockaddr_in6)){ 77 return EINVAL; 78 } 79 address_in6 = (struct sockaddr_in6 *) addr; 80 *port = ntohs(address_in6->sin6_port); 81 break; 82 default: 83 return EAFNOSUPPORT; 84 } 88 85 return EOK; 89 86 } … … 115 112 return EBADMEM; 116 113 117 *packet_dimension = packet_dimensions_find(packet_dimensions, 118 device_id); 114 *packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 119 115 if (!*packet_dimension) { 120 116 /* Ask for and remember them if not found */ … … 140 136 } 141 137 142 int 143 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, 144 device_id_t device_id, size_t content) 145 { 138 int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){ 146 139 packet_dimension_ref packet_dimension; 147 140 148 141 packet_dimension = packet_dimensions_find(packet_dimensions, device_id); 149 if (!packet_dimension)142 if(! packet_dimension){ 150 143 return ENOENT; 144 } 151 145 packet_dimension->content = content; 152 153 if (device_id != DEVICE_INVALID_ID) { 154 packet_dimension = packet_dimensions_find(packet_dimensions, 155 DEVICE_INVALID_ID); 156 157 if (packet_dimension) { 158 if (packet_dimension->content >= content) 146 if(device_id != DEVICE_INVALID_ID){ 147 packet_dimension = packet_dimensions_find(packet_dimensions, DEVICE_INVALID_ID); 148 if(packet_dimension){ 149 if(packet_dimension->content >= content){ 159 150 packet_dimension->content = content; 160 else 161 packet_dimensions_exclude(packet_dimensions, 162 DEVICE_INVALID_ID); 163 151 }else{ 152 packet_dimensions_exclude(packet_dimensions, DEVICE_INVALID_ID); 153 } 164 154 } 165 155 } 166 167 156 return EOK; 168 157 } … … 170 159 int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port) 171 160 { 172 struct sockaddr_in * address_in;173 struct sockaddr_in6 * address_in6;161 struct sockaddr_in * address_in; 162 struct sockaddr_in6 * address_in6; 174 163 size_t length; 175 164 … … 199 188 } 200 189 201 int 202 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, 203 services_t error) 204 { 190 int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error){ 205 191 packet_t next; 206 uint8_t * src;192 uint8_t * src; 207 193 int length; 208 194 … … 213 199 214 200 length = packet_get_addr(packet, &src, NULL); 215 if ((length > 0) && (!error) && (icmp_phone >= 0) && 216 // set both addresses to the source one (avoids the source address 217 // deletion before setting the destination one) 218 (packet_set_addr(packet, src, src, (size_t) length) == EOK)) { 201 if((length > 0) 202 && (! error) 203 && (icmp_phone >= 0) 204 // set both addresses to the source one (avoids the source address deletion before setting the destination one) 205 && (packet_set_addr(packet, src, src, (size_t) length) == EOK)){ 219 206 return EOK; 220 } else207 }else{ 221 208 pq_release_remote(packet_phone, packet_get_id(packet)); 222 209 } 223 210 return ENOENT; 224 211 } 225 212 226 int 227 tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, 228 const packet_dimension_ref dimension, const struct sockaddr *addr, 229 socklen_t addrlen) 230 { 213 int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen){ 231 214 ERROR_DECLARE; 232 215 … … 235 218 void * data; 236 219 237 if (!dimension)238 return EINVAL; 239 220 if(! dimension){ 221 return EINVAL; 222 } 240 223 // get the data length 241 if (!async_data_write_receive(&callid, &length))242 return EINVAL; 243 224 if(! async_data_write_receive(&callid, &length)){ 225 return EINVAL; 226 } 244 227 // get a new packet 245 *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, 246 prefix + dimension->prefix, dimension->suffix); 247 if (!packet) 228 *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix); 229 if(! packet){ 248 230 return ENOMEM; 249 231 } 250 232 // allocate space in the packet 251 233 data = packet_suffix(*packet, length); 252 if (!data){234 if(! data){ 253 235 pq_release_remote(packet_phone, packet_get_id(*packet)); 254 236 return ENOMEM; 255 237 } 256 257 238 // read the data into the packet 258 if (ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) || 259 // set the packet destination address 260 ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, 261 addrlen))) { 239 if(ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) 240 // set the packet destination address 241 || ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen))){ 262 242 pq_release_remote(packet_phone, packet_get_id(*packet)); 263 243 return ERROR_CODE; 264 244 } 265 266 245 return (int) length; 267 246 }
Note:
See TracChangeset
for help on using the changeset viewer.