Changeset 2a786f9 in mainline for uspace/lib/net/tl/tl_common.c


Ignore:
Timestamp:
2010-09-22T19:07:02Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ec1bdc8
Parents:
dc94cb2 (diff), 921a860 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/net.

File:
1 edited

Legend:

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

    rdc94cb2 r2a786f9  
    5858DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
    5959
    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)){
     60int
     61tl_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))
    7079                                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
    8588        return EOK;
    8689}
     
    112115                return EBADMEM;
    113116       
    114         *packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
     117        *packet_dimension = packet_dimensions_find(packet_dimensions,
     118            device_id);
    115119        if (!*packet_dimension) {
    116120                /* Ask for and remember them if not found */
     
    136140}
    137141
    138 int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){
     142int
     143tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
     144    device_id_t device_id, size_t content)
     145{
    139146        packet_dimension_ref packet_dimension;
    140147
    141148        packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
    142         if(! packet_dimension){
     149        if (!packet_dimension)
    143150                return ENOENT;
    144         }
    145151        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)
    150159                                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
    154164                }
    155165        }
     166
    156167        return EOK;
    157168}
     
    159170int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
    160171{
    161         struct sockaddr_in * address_in;
    162         struct sockaddr_in6 * address_in6;
     172        struct sockaddr_in *address_in;
     173        struct sockaddr_in6 *address_in6;
    163174        size_t length;
    164175
     
    188199}
    189200
    190 int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error){
     201int
     202tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet,
     203    services_t error)
     204{
    191205        packet_t next;
    192         uint8_t * src;
     206        uint8_t *src;
    193207        int length;
    194208
     
    199213       
    200214        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)) {
    206219                return EOK;
    207         }else{
     220        } else
    208221                pq_release_remote(packet_phone, packet_get_id(packet));
    209         }
     222
    210223        return ENOENT;
    211224}
    212225
    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){
     226int
     227tl_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{
    214231        ERROR_DECLARE;
    215232
     
    218235        void * data;
    219236
    220         if(! dimension){
    221                 return EINVAL;
    222         }
     237        if (!dimension)
     238                return EINVAL;
     239
    223240        // 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
    227244        // 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)
    230248                return ENOMEM;
    231         }
     249
    232250        // allocate space in the packet
    233251        data = packet_suffix(*packet, length);
    234         if(! data){
     252        if (!data) {
    235253                pq_release_remote(packet_phone, packet_get_id(*packet));
    236254                return ENOMEM;
    237255        }
     256
    238257        // 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))) {
    242262                pq_release_remote(packet_phone, packet_get_id(*packet));
    243263                return ERROR_CODE;
    244264        }
     265
    245266        return (int) length;
    246267}
Note: See TracChangeset for help on using the changeset viewer.