Changeset 2fa0ad9 in mainline
- Timestamp:
- 2010-09-21T21:02:04Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7282582
- Parents:
- 7c8267b
- Location:
- uspace/lib/net
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/net/generic/net_remote.c
r7c8267b r2fa0ad9 47 47 #include <net_net_messages.h> 48 48 49 int net_connect_module(services_t service){ 49 int net_connect_module(services_t service) 50 { 50 51 return connect_to_service(SERVICE_NETWORKING); 51 52 } 52 53 53 void net_free_settings(measured_string_ref settings, char * data){ 54 if(settings){ 54 void net_free_settings(measured_string_ref settings, char * data) 55 { 56 if (settings) 55 57 free(settings); 56 } 57 if (data){58 59 if (data) 58 60 free(data); 59 }60 61 } 61 62 62 int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){ 63 return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, * configuration, count, configuration, data); 63 int 64 net_get_conf_req(int net_phone, measured_string_ref * configuration, 65 size_t count, char ** data) 66 { 67 return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, 68 *configuration, count, configuration, data); 64 69 } 65 70 66 int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){ 67 return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data); 71 int 72 net_get_device_conf_req(int net_phone, device_id_t device_id, 73 measured_string_ref * configuration, size_t count, char ** data) 74 { 75 return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 76 device_id, 0, *configuration, count, configuration, data); 68 77 } 69 78 -
uspace/lib/net/generic/packet_remote.c
r7c8267b r2fa0ad9 64 64 * 65 65 */ 66 static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){ 66 static int 67 packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size) 68 { 67 69 ERROR_DECLARE; 68 70 69 71 ipc_call_t answer; 70 72 aid_t message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer); 73 71 74 *packet = (packet_t) as_get_mappable_page(size); 72 75 if (ERROR_OCCURRED(async_share_in_start_0_0(phone, *packet, size)) || … … 91 94 92 95 *packet = pm_find(packet_id); 93 if (! (*packet)) {96 if (!*packet) { 94 97 ipcarg_t size; 95 98 96 ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size)); 99 ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, 100 packet_id, &size)); 97 101 ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size)); 98 102 } 99 if ((* * packet).next) {103 if ((*packet)->next) { 100 104 packet_t next; 101 105 102 return packet_translate_remote(phone, &next, (* * packet).next);106 return packet_translate_remote(phone, &next, (*packet)->next); 103 107 } 104 108 … … 114 118 ipcarg_t size; 115 119 116 if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content,117 addr_len, max_prefix, max_suffix, &packet_id, &size)))120 if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, 121 max_content, addr_len, max_prefix, max_suffix, &packet_id, &size))) 118 122 return NULL; 119 123 … … 121 125 packet_t packet = pm_find(packet_id); 122 126 if (!packet) { 123 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))) 127 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, 128 size))) 124 129 return NULL; 125 130 } … … 141 146 packet_t packet = pm_find(packet_id); 142 147 if (!packet) { 143 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))) 148 if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, 149 size))) 144 150 return NULL; 145 151 } -
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.