Ignore:
File:
1 edited

Legend:

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

    r2fa0ad9 r7c8267b  
    5858DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
    5959
    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))
     60int 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)){
    7970                                return EINVAL;
    80 
    81                 address_in6 = (struct sockaddr_in6 *) addr;
    82                 *port = ntohs(address_in6->sin6_port);
    83                 break;
    84         default:
    85                 return EAFNOSUPPORT;
    86         }
    87 
     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        }
    8885        return EOK;
    8986}
     
    115112                return EBADMEM;
    116113       
    117         *packet_dimension = packet_dimensions_find(packet_dimensions,
    118             device_id);
     114        *packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
    119115        if (!*packet_dimension) {
    120116                /* Ask for and remember them if not found */
     
    140136}
    141137
    142 int
    143 tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions,
    144     device_id_t device_id, size_t content)
    145 {
     138int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){
    146139        packet_dimension_ref packet_dimension;
    147140
    148141        packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
    149         if (!packet_dimension)
     142        if(! packet_dimension){
    150143                return ENOENT;
     144        }
    151145        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)
     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){
    159150                                packet_dimension->content = content;
    160                         else
    161                                 packet_dimensions_exclude(packet_dimensions,
    162                                     DEVICE_INVALID_ID);
    163 
     151                        }else{
     152                                packet_dimensions_exclude(packet_dimensions, DEVICE_INVALID_ID);
     153                        }
    164154                }
    165155        }
    166 
    167156        return EOK;
    168157}
     
    170159int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port)
    171160{
    172         struct sockaddr_in *address_in;
    173         struct sockaddr_in6 *address_in6;
     161        struct sockaddr_in * address_in;
     162        struct sockaddr_in6 * address_in6;
    174163        size_t length;
    175164
     
    199188}
    200189
    201 int
    202 tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet,
    203     services_t error)
    204 {
     190int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error){
    205191        packet_t next;
    206         uint8_t *src;
     192        uint8_t * src;
    207193        int length;
    208194
     
    213199       
    214200        length = packet_get_addr(packet, &src, NULL);
    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)) {
     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)){
    219206                return EOK;
    220         } else
     207        }else{
    221208                pq_release_remote(packet_phone, packet_get_id(packet));
    222 
     209        }
    223210        return ENOENT;
    224211}
    225212
    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 {
     213int 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){
    231214        ERROR_DECLARE;
    232215
     
    235218        void * data;
    236219
    237         if (!dimension)
    238                 return EINVAL;
    239 
     220        if(! dimension){
     221                return EINVAL;
     222        }
    240223        // get the data length
    241         if (!async_data_write_receive(&callid, &length))
    242                 return EINVAL;
    243 
     224        if(! async_data_write_receive(&callid, &length)){
     225                return EINVAL;
     226        }
    244227        // get a new packet
    245         *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len,
    246             prefix + dimension->prefix, dimension->suffix);
    247         if (!packet)
     228        *packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix);
     229        if(! packet){
    248230                return ENOMEM;
    249 
     231        }
    250232        // allocate space in the packet
    251233        data = packet_suffix(*packet, length);
    252         if (!data) {
     234        if(! data){
    253235                pq_release_remote(packet_phone, packet_get_id(*packet));
    254236                return ENOMEM;
    255237        }
    256 
    257238        // read the data into the packet
    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))) {
     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))){
    262242                pq_release_remote(packet_phone, packet_get_id(*packet));
    263243                return ERROR_CODE;
    264244        }
    265 
    266245        return (int) length;
    267246}
Note: See TracChangeset for help on using the changeset viewer.