Changeset 71b00dcc in mainline for uspace/srv/net/inet.c


Ignore:
Timestamp:
2010-03-07T22:51:38Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
60ab6c3
Parents:
b5cbff4 (diff), 31c80a5 (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:~lukasmejdrech/helenos/network.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/inet.c

    rb5cbff4 r71b00dcc  
    4545#include "include/socket_codes.h"
    4646
    47 int inet_pton( uint16_t family, const char * address, uint8_t * data ){
    48         const char *    next;
    49         char *                  last;
    50         int                             index;
    51         int                             count;
    52         int                             base;
    53         size_t                  bytes;
    54         size_t                  shift;
    55         unsigned long   value;
     47int inet_pton(uint16_t family, const char * address, uint8_t * data){
     48        const char * next;
     49        char * last;
     50        int index;
     51        int count;
     52        int base;
     53        size_t bytes;
     54        size_t shift;
     55        unsigned long value;
    5656
    57         if( ! data ) return EINVAL;
    58         switch( family ){
     57        if(! data){
     58                return EINVAL;
     59        }
     60        switch(family){
    5961                case AF_INET:
    6062                        count = 4;
     
    7072                        return ENOTSUP;
    7173        }
    72         if( ! address ){
    73                 bzero( data, count );
     74        if(! address){
     75                bzero(data, count);
    7476                return ENOENT;
    7577        }
     
    7779        index = 0;
    7880        do{
    79                 if( next && ( * next )){
    80                         if( index ) ++ next;
    81                         value = strtoul( next, & last, base );
     81                if(next && (*next)){
     82                        if(index){
     83                                ++ next;
     84                        }
     85                        value = strtoul(next, &last, base);
    8286                        next = last;
    8387                        shift = bytes - 1;
    8488                        do{
    8589                                // like little endian
    86                                 data[ index + shift ] = value;
     90                                data[index + shift] = value;
    8791                                value >>= 8;
    88                         }while( shift -- );
     92                        }while(shift --);
    8993                        index += bytes;
    9094                }else{
    91                         bzero( data + index, count - index );
     95                        bzero(data + index, count - index);
    9296                        return EOK;
    9397                }
    94         }while( index < count );
     98        }while(index < count);
    9599        return EOK;
    96100}
    97101
    98 int inet_ntop( uint16_t family, const uint8_t * data, char * address, size_t length ){
    99         if(( ! data ) || ( ! address )) return EINVAL;
    100         switch( family ){
    101                 case AF_INET:   if( length < INET_ADDRSTRLEN ) return ENOMEM;
    102                                                 snprintf( address, length, "%hhu.%hhu.%hhu.%hhu", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ] );
    103                                                 return EOK;
    104                 case AF_INET6:  if( length < INET6_ADDRSTRLEN ) return ENOMEM;
    105                                                 snprintf( address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[ 0 ], data[ 1 ], data[ 2 ], data[ 3 ], data[ 4 ], data[ 5 ], data[ 6 ], data[ 7 ], data[ 8 ], data[ 9 ], data[ 10 ], data[ 11 ], data[ 12 ], data[ 13 ], data[ 14 ], data[ 15 ] );
    106                                                 return EOK;
    107                 default:                return ENOTSUP;
     102int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length){
     103        if((! data) || (! address)){
     104                return EINVAL;
     105        }
     106        switch(family){
     107                case AF_INET:
     108                        if(length < INET_ADDRSTRLEN){
     109                                return ENOMEM;
     110                        }
     111                        snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", data[0], data[1], data[2], data[3]);
     112                        return EOK;
     113                case AF_INET6:
     114                        if(length < INET6_ADDRSTRLEN){
     115                                return ENOMEM;
     116                        }
     117                        snprintf(address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);
     118                        return EOK;
     119                default:
     120                        return ENOTSUP;
    108121        }
    109122}
Note: See TracChangeset for help on using the changeset viewer.