Changes in uspace/srv/net/inet.c [21580dd:aadf01e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/inet.c
r21580dd raadf01e 45 45 #include "include/socket_codes.h" 46 46 47 int inet_pton( uint16_t family, const char * address, uint8_t * data){48 const char * 49 char * 50 int 51 int 52 int 53 size_t 54 size_t 55 unsigned long 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; 56 56 57 if( ! data ) return EINVAL; 58 switch( family ){ 57 if(! data){ 58 return EINVAL; 59 } 60 switch(family){ 59 61 case AF_INET: 60 62 count = 4; … … 70 72 return ENOTSUP; 71 73 } 72 if( ! address){73 bzero( data, count);74 if(! address){ 75 bzero(data, count); 74 76 return ENOENT; 75 77 } … … 77 79 index = 0; 78 80 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); 82 86 next = last; 83 87 shift = bytes - 1; 84 88 do{ 85 89 // like little endian 86 data[ index + shift] = value;90 data[index + shift] = value; 87 91 value >>= 8; 88 }while( shift --);92 }while(shift --); 89 93 index += bytes; 90 94 }else{ 91 bzero( data + index, count - index);95 bzero(data + index, count - index); 92 96 return EOK; 93 97 } 94 }while( index < count);98 }while(index < count); 95 99 return EOK; 96 100 } 97 101 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; 102 int 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; 108 121 } 109 122 }
Note:
See TracChangeset
for help on using the changeset viewer.