Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/net/tl/tl_common.c

    r28a3e74 r84c20da  
    2727 */
    2828
    29 /** @addtogroup libnet
     29/** @addtogroup libnet 
    3030 * @{
    3131 */
     
    3939#include <packet_client.h>
    4040#include <packet_remote.h>
    41 #include <icmp_remote.h>
     41#include <icmp_interface.h>
    4242#include <ip_remote.h>
    4343#include <ip_interface.h>
    44 #include <tl_remote.h>
     44#include <tl_interface.h>
    4545
    4646#include <net/socket_codes.h>
     
    5454#include <ipc/services.h>
    5555#include <errno.h>
     56#include <err.h>
    5657
    5758DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
     
    6465 * @param[in] addrlen   The address length.
    6566 * @param[out] port     The set port.
    66  * @return              EOK on success.
    67  * @return              EINVAL if the address length does not match the address
     67 * @returns             EOK on success.
     68 * @returns             EINVAL if the address length does not match the address
    6869 *                      family.
    69  * @return              EAFNOSUPPORT if the address family is not supported.
     70 * @returns             EAFNOSUPPORT if the address family is not supported.
    7071 */
    7172int
     
    120121int
    121122tl_get_ip_packet_dimension(int ip_phone,
    122     packet_dimensions_t *packet_dimensions, device_id_t device_id,
    123     packet_dimension_t **packet_dimension)
    124 {
    125         int rc;
     123    packet_dimensions_ref packet_dimensions, device_id_t device_id,
     124    packet_dimension_ref *packet_dimension)
     125{
     126        ERROR_DECLARE;
    126127       
    127128        if (!packet_dimension)
     
    136137                        return ENOMEM;
    137138               
    138                 rc = ip_packet_size_req(ip_phone, device_id, *packet_dimension);
    139                 if (rc != EOK) {
     139                if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
     140                    *packet_dimension))) {
    140141                        free(*packet_dimension);
    141                         return rc;
     142                        return ERROR_CODE;
    142143                }
    143144               
    144                 rc = packet_dimensions_add(packet_dimensions, device_id,
     145                ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
    145146                    *packet_dimension);
    146                 if (rc < 0) {
     147                if (ERROR_CODE < 0) {
    147148                        free(*packet_dimension);
    148                         return rc;
     149                        return ERROR_CODE;
    149150                }
    150151        }
     
    158159 * @param[in] device_id The device identifier.
    159160 * @param[in] content   The new maximum content size.
    160  * @return              EOK on success.
     161 * @returns             EOK on success.
    161162 * @return              ENOENT if the packet dimension is not cached.
    162163 */
    163164int
    164 tl_update_ip_packet_dimension(packet_dimensions_t *packet_dimensions,
     165tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
    165166    device_id_t device_id, size_t content)
    166167{
    167         packet_dimension_t *packet_dimension;
     168        packet_dimension_ref packet_dimension;
    168169
    169170        packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
     
    182183                        else
    183184                                packet_dimensions_exclude(packet_dimensions,
    184                                     DEVICE_INVALID_ID, free);
     185                                    DEVICE_INVALID_ID);
    185186                }
    186187        }
     
    196197 * @param[in] addrlen   The address length.
    197198 * @param[in] port      The port to be set.
    198  * @return              EOK on success.
    199  * @return              EINVAL if the address length does not match the address
     199 * @returns             EOK on success.
     200 * @returns             EINVAL if the address length does not match the address
    200201 *                      family.
    201  * @return              EAFNOSUPPORT if the address family is not supported.
     202 * @returns             EAFNOSUPPORT if the address family is not supported.
    202203 */
    203204int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
     
    244245 * @param[in] error     The packet error reporting service. Prefixes the
    245246 *                      received packet.
    246  * @return              EOK on success.
    247  * @return              ENOENT if no packet may be sent.
    248  */
    249 int
    250 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t *packet,
     247 * @returns             EOK on success.
     248 * @returns             ENOENT if no packet may be sent.
     249 */
     250int
     251tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet,
    251252    services_t error)
    252253{
    253         packet_t *next;
     254        packet_t next;
    254255        uint8_t *src;
    255256        int length;
    256257
    257         /* Detach the first packet and release the others */
     258        // detach the first packet and release the others
    258259        next = pq_detach(packet);
    259260        if (next)
     
    262263        length = packet_get_addr(packet, &src, NULL);
    263264        if ((length > 0) && (!error) && (icmp_phone >= 0) &&
    264             /*
    265              * Set both addresses to the source one (avoids the source address
    266              * deletion before setting the destination one)
    267              */
     265            // set both addresses to the source one (avoids the source address
     266            // deletion before setting the destination one)
    268267            (packet_set_addr(packet, src, src, (size_t) length) == EOK)) {
    269268                return EOK;
     
    282281 * @param[in] addr      The destination address.
    283282 * @param[in] addrlen   The address length.
    284  * @return              Number of bytes received.
    285  * @return              EINVAL if the client does not send data.
    286  * @return              ENOMEM if there is not enough memory left.
    287  * @return              Other error codes as defined for the
     283 * @returns             Number of bytes received.
     284 * @returns             EINVAL if the client does not send data.
     285 * @returns             ENOMEM if there is not enough memory left.
     286 * @returns             Other error codes as defined for the
    288287 *                      async_data_read_finalize() function.
    289288 */
    290289int
    291 tl_socket_read_packet_data(int packet_phone, packet_t **packet, size_t prefix,
    292     const packet_dimension_t *dimension, const struct sockaddr *addr,
     290tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix,
     291    const packet_dimension_ref dimension, const struct sockaddr *addr,
    293292    socklen_t addrlen)
    294293{
     294        ERROR_DECLARE;
     295
    295296        ipc_callid_t callid;
    296297        size_t length;
    297         void *data;
    298         int rc;
     298        void * data;
    299299
    300300        if (!dimension)
    301301                return EINVAL;
    302302
    303         /* Get the data length */
     303        // get the data length
    304304        if (!async_data_write_receive(&callid, &length))
    305305                return EINVAL;
    306306
    307         /* Get a new packet */
     307        // get a new packet
    308308        *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len,
    309309            prefix + dimension->prefix, dimension->suffix);
     
    311311                return ENOMEM;
    312312
    313         /* Allocate space in the packet */
     313        // allocate space in the packet
    314314        data = packet_suffix(*packet, length);
    315315        if (!data) {
     
    318318        }
    319319
    320         /* Read the data into the packet */
    321         rc = async_data_write_finalize(callid, data, length);
    322         if (rc != EOK) {
     320        // read the data into the packet
     321        if (ERROR_OCCURRED(async_data_write_finalize(callid, data, length)) ||
     322            // set the packet destination address
     323            ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr,
     324            addrlen))) {
    323325                pq_release_remote(packet_phone, packet_get_id(*packet));
    324                 return rc;
    325         }
    326        
    327         /* Set the packet destination address */
    328         rc = packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen);
    329         if (rc != EOK) {
    330                 pq_release_remote(packet_phone, packet_get_id(*packet));
    331                 return rc;
     326                return ERROR_CODE;
    332327        }
    333328
Note: See TracChangeset for help on using the changeset viewer.