Changes in / [bbc74af7:eb221e5] in mainline
- Location:
- uspace
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/net/modules.c
rbbc74af7 reb221e5 198 198 } 199 199 200 /** Receives data from the other party. 201 * 202 * The received data buffer is allocated and returned. 203 * 204 * @param[out] data The data buffer to be filled. 205 * @param[out] length The buffer length. 206 * @return EOK on success. 207 * @return EBADMEM if the data or the length parameter is NULL. 208 * @return EINVAL if the client does not send data. 209 * @return ENOMEM if there is not enough memory left. 210 * @return Other error codes as defined for the 211 * async_data_write_finalize() function. 212 */ 213 int data_receive(void **data, size_t *length) 214 { 215 ipc_callid_t callid; 216 int rc; 217 218 if (!data || !length) 219 return EBADMEM; 220 221 // fetch the request 222 if (!async_data_write_receive(&callid, length)) 223 return EINVAL; 224 225 // allocate the buffer 226 *data = malloc(*length); 227 if (!*data) 228 return ENOMEM; 229 230 // fetch the data 231 rc = async_data_write_finalize(callid, *data, *length); 232 if (rc != EOK) { 233 free(data); 234 return rc; 235 } 236 237 return EOK; 238 } 239 200 240 /** Replies the data to the other party. 201 241 * -
uspace/lib/c/include/net/modules.h
rbbc74af7 reb221e5 49 49 #include <sys/time.h> 50 50 51 /** Converts the data length between different types. 52 * 53 * @param[in] type_from The source type. 54 * @param[in] type_to The destination type. 55 * @param[in] count The number units of the source type size. 56 */ 57 #define CONVERT_SIZE(type_from, type_to, count) \ 58 ((sizeof(type_from) / sizeof(type_to)) * (count)) 59 60 /** Registers the module service at the name server. 61 * 62 * @param[in] me The module service. 63 * @param[out] phonehash The created phone hash. 64 */ 65 #define REGISTER_ME(me, phonehash) \ 66 ipc_connect_to_me(PHONE_NS, (me), 0, 0, (phonehash)) 67 51 68 /** Connect to the needed module function type definition. 52 69 * … … 63 80 extern int connect_to_service(services_t); 64 81 extern int connect_to_service_timeout(services_t, suseconds_t); 82 extern int data_receive(void **, size_t *); 65 83 extern int data_reply(void *, size_t); 66 84 extern void refresh_answer(ipc_call_t *, int *); -
uspace/srv/hw/netif/dp8390/dp8390_module.c
rbbc74af7 reb221e5 197 197 return rc; 198 198 address->value = (char *) (&((dpeth_t *) device->specific)->de_address); 199 address->length = sizeof(ether_addr_t);199 address->length = CONVERT_SIZE(ether_addr_t, char, 1); 200 200 return EOK; 201 201 } … … 310 310 async_set_interrupt_received(irq_handler); 311 311 312 return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0,0, &phonehash);312 return REGISTER_ME(SERVICE_DP8390, &phonehash); 313 313 } 314 314 -
uspace/srv/net/il/arp/arp.c
rbbc74af7 reb221e5 483 483 des_proto = des_hw + header->hardware_length; 484 484 trans = arp_addr_find(&proto->addresses, (char *) src_proto, 485 header->protocol_length);485 CONVERT_SIZE(uint8_t, char, header->protocol_length)); 486 486 /* Exists? */ 487 487 if (trans && trans->hw_addr) { 488 if (trans->hw_addr->length != header->hardware_length) 488 if (trans->hw_addr->length != CONVERT_SIZE(uint8_t, char, 489 header->hardware_length)) { 489 490 return EINVAL; 491 } 490 492 memcpy(trans->hw_addr->value, src_hw, trans->hw_addr->length); 491 493 } 492 494 /* Is my protocol address? */ 493 if (proto->addr->length != header->protocol_length) 495 if (proto->addr->length != CONVERT_SIZE(uint8_t, char, 496 header->protocol_length)) { 494 497 return EINVAL; 498 } 495 499 if (!str_lcmp(proto->addr->value, (char *) des_proto, 496 500 proto->addr->length)) { … … 503 507 fibril_condvar_initialize(&trans->cv); 504 508 rc = arp_addr_add(&proto->addresses, (char *) src_proto, 505 header->protocol_length, trans); 509 CONVERT_SIZE(uint8_t, char, header->protocol_length), 510 trans); 506 511 if (rc != EOK) { 507 512 /* The generic char map has already freed trans! */ … … 511 516 if (!trans->hw_addr) { 512 517 trans->hw_addr = measured_string_create_bulk( 513 (char *) src_hw, header->hardware_length); 518 (char *) src_hw, CONVERT_SIZE(uint8_t, char, 519 header->hardware_length)); 514 520 if (!trans->hw_addr) 515 521 return ENOMEM; … … 600 606 601 607 /* ARP packet content size = header + (address + translation) * 2 */ 602 length = 8 + 2 * (proto->addr->length + device->addr->length); 608 length = 8 + 2 * (CONVERT_SIZE(char, uint8_t, proto->addr->length) + 609 CONVERT_SIZE(char, uint8_t, device->addr->length)); 603 610 if (length > device->packet_dimension.content) 604 611 return ELIMIT; … … 633 640 634 641 rc = packet_set_addr(packet, (uint8_t *) device->addr->value, 635 (uint8_t *) device->broadcast_addr->value, device->addr->length); 642 (uint8_t *) device->broadcast_addr->value, 643 CONVERT_SIZE(char, uint8_t, device->addr->length)); 636 644 if (rc != EOK) { 637 645 pq_release_remote(arp_globals.net_phone, packet_get_id(packet)); -
uspace/srv/net/il/arp/arp_module.c
rbbc74af7 reb221e5 79 79 goto out; 80 80 81 rc = ipc_connect_to_me(PHONE_NS, SERVICE_ARP, 0, 0, &phonehash);81 rc = REGISTER_ME(SERVICE_ARP, &phonehash); 82 82 if (rc != EOK) 83 83 goto out; -
uspace/srv/net/il/ip/ip.c
rbbc74af7 reb221e5 442 442 if (route) { 443 443 address.value = (char *) &route->address.s_addr; 444 address.length = sizeof(in_addr_t);444 address.length = CONVERT_SIZE(in_addr_t, char, 1); 445 445 446 446 rc = arp_device_req(ip_netif->arp->phone, … … 639 639 if (destination) { 640 640 rc = packet_set_addr(packet, NULL, (uint8_t *) destination->value, 641 destination->length);641 CONVERT_SIZE(char, uint8_t, destination->length)); 642 642 } else { 643 643 rc = packet_set_addr(packet, NULL, NULL, 0); … … 687 687 rc = packet_set_addr(next, NULL, 688 688 (uint8_t *) destination->value, 689 destination->length); 689 CONVERT_SIZE(char, uint8_t, 690 destination->length)); 690 691 if (rc != EOK) { 691 692 free(last_header); … … 717 718 rc = packet_set_addr(next, NULL, 718 719 (uint8_t *) destination->value, 719 destination->length);720 CONVERT_SIZE(char, uint8_t, destination->length)); 720 721 if (rc != EOK) { 721 722 free(last_header); … … 1005 1006 destination.value = route->gateway.s_addr ? 1006 1007 (char *) &route->gateway.s_addr : (char *) &dest.s_addr; 1007 destination.length = sizeof(dest.s_addr);1008 destination.length = CONVERT_SIZE(dest.s_addr, char, 1); 1008 1009 1009 1010 rc = arp_translate_req(netif->arp->phone, netif->device_id, … … 1757 1758 // clear the ARP mapping if any 1758 1759 address.value = (char *) &header->destination_address; 1759 address.length = sizeof(header->destination_address); 1760 address.length = CONVERT_SIZE(uint8_t, char, 1761 sizeof(header->destination_address)); 1760 1762 arp_clear_address_req(netif->arp->phone, 1761 1763 netif->device_id, SERVICE_IP, &address); … … 1949 1951 1950 1952 case NET_IP_GET_ROUTE: 1951 rc = async_data_write_accept((void **) &addr, false, 0, 0, 0, 1952 &addrlen); 1953 rc = data_receive((void **) &addr, &addrlen); 1953 1954 if (rc != EOK) 1954 1955 return rc; -
uspace/srv/net/il/ip/ip_module.c
rbbc74af7 reb221e5 80 80 goto out; 81 81 82 rc = ipc_connect_to_me(PHONE_NS, SERVICE_IP, 0, 0, &phonehash);82 rc = REGISTER_ME(SERVICE_IP, &phonehash); 83 83 if (rc != EOK) 84 84 goto out; -
uspace/srv/net/net/net.c
rbbc74af7 reb221e5 335 335 goto out; 336 336 337 rc = ipc_connect_to_me(PHONE_NS, SERVICE_NETWORKING, 0, 0, &phonehash);337 rc = REGISTER_ME(SERVICE_NETWORKING, &phonehash); 338 338 if (rc != EOK) 339 339 goto out; -
uspace/srv/net/netif/lo/lo.c
rbbc74af7 reb221e5 166 166 sysarg_t phonehash; 167 167 168 return ipc_connect_to_me(PHONE_NS, SERVICE_LO, 0, 0, &phonehash);168 return REGISTER_ME(SERVICE_LO, &phonehash); 169 169 } 170 170 -
uspace/srv/net/nil/eth/eth.c
rbbc74af7 reb221e5 201 201 202 202 eth_globals.broadcast_addr = 203 measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF", ETH_ADDR); 203 measured_string_create_bulk("\xFF\xFF\xFF\xFF\xFF\xFF", 204 CONVERT_SIZE(uint8_t, char, ETH_ADDR)); 204 205 if (!eth_globals.broadcast_addr) { 205 206 rc = ENOMEM; -
uspace/srv/net/nil/eth/eth_module.c
rbbc74af7 reb221e5 66 66 goto out; 67 67 68 rc = ipc_connect_to_me(PHONE_NS, SERVICE_ETHERNET, 0, 0, &phonehash);68 rc = REGISTER_ME(SERVICE_ETHERNET, &phonehash); 69 69 if (rc != EOK) 70 70 goto out; -
uspace/srv/net/nil/nildummy/nildummy_module.c
rbbc74af7 reb221e5 67 67 goto out; 68 68 69 rc = ipc_connect_to_me(PHONE_NS, SERVICE_NILDUMMY, 0, 0, &phonehash);69 rc = REGISTER_ME(SERVICE_NILDUMMY, &phonehash); 70 70 if (rc != EOK) 71 71 goto out; -
uspace/srv/net/tl/icmp/icmp_module.c
rbbc74af7 reb221e5 74 74 goto out; 75 75 76 rc = ipc_connect_to_me(PHONE_NS, SERVICE_ICMP, 0, 0, &phonehash);76 rc = REGISTER_ME(SERVICE_ICMP, &phonehash); 77 77 if (rc != EOK) 78 78 goto out; -
uspace/srv/net/tl/tcp/tcp.c
rbbc74af7 reb221e5 1365 1365 1366 1366 case NET_SOCKET_BIND: 1367 res = async_data_write_accept((void **) &addr, false, 1368 0, 0, 0, &addrlen); 1367 res = data_receive((void **) &addr, &addrlen); 1369 1368 if (res != EOK) 1370 1369 break; … … 1403 1402 1404 1403 case NET_SOCKET_CONNECT: 1405 res = async_data_write_accept((void **) &addr, false, 1406 0, 0, 0, &addrlen); 1404 res = data_receive((void **) &addr, &addrlen); 1407 1405 if (res != EOK) 1408 1406 break; … … 1455 1453 1456 1454 case NET_SOCKET_SENDTO: 1457 res = async_data_write_accept((void **) &addr, false, 1458 0, 0, 0, &addrlen); 1455 res = data_receive((void **) &addr, &addrlen); 1459 1456 if (res != EOK) 1460 1457 break; -
uspace/srv/net/tl/tcp/tcp_module.c
rbbc74af7 reb221e5 75 75 goto out; 76 76 77 rc = ipc_connect_to_me(PHONE_NS, SERVICE_TCP, 0, 0, &phonehash);77 rc = REGISTER_ME(SERVICE_TCP, &phonehash); 78 78 if (rc != EOK) 79 79 goto out; -
uspace/srv/net/tl/udp/udp.c
rbbc74af7 reb221e5 771 771 772 772 case NET_SOCKET_BIND: 773 res = async_data_write_accept((void **) &addr, false, 774 0, 0, 0, &addrlen); 773 res = data_receive((void **) &addr, &addrlen); 775 774 if (res != EOK) 776 775 break; … … 785 784 786 785 case NET_SOCKET_SENDTO: 787 res = async_data_write_accept((void **) &addr, false, 788 0, 0, 0, &addrlen); 786 res = data_receive((void **) &addr, &addrlen); 789 787 if (res != EOK) 790 788 break; -
uspace/srv/net/tl/udp/udp_module.c
rbbc74af7 reb221e5 75 75 goto out; 76 76 77 rc = ipc_connect_to_me(PHONE_NS, SERVICE_UDP, 0, 0, &phonehash);77 rc = REGISTER_ME(SERVICE_UDP, &phonehash); 78 78 if (rc != EOK) 79 79 goto out;
Note:
See TracChangeset
for help on using the changeset viewer.