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