Changes in uspace/srv/net/inet.c [aadf01e:21580dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/srv/net/inet.c ¶
raadf01e r21580dd 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){ 58 return EINVAL; 59 } 60 switch(family){ 57 if( ! data ) return EINVAL; 58 switch( family ){ 61 59 case AF_INET: 62 60 count = 4; … … 72 70 return ENOTSUP; 73 71 } 74 if( ! address){75 bzero( data, count);72 if( ! address ){ 73 bzero( data, count ); 76 74 return ENOENT; 77 75 } … … 79 77 index = 0; 80 78 do{ 81 if(next && (*next)){ 82 if(index){ 83 ++ next; 84 } 85 value = strtoul(next, &last, base); 79 if( next && ( * next )){ 80 if( index ) ++ next; 81 value = strtoul( next, & last, base ); 86 82 next = last; 87 83 shift = bytes - 1; 88 84 do{ 89 85 // like little endian 90 data[ index + shift] = value;86 data[ index + shift ] = value; 91 87 value >>= 8; 92 }while( shift --);88 }while( shift -- ); 93 89 index += bytes; 94 90 }else{ 95 bzero( data + index, count - index);91 bzero( data + index, count - index ); 96 92 return EOK; 97 93 } 98 }while( index < count);94 }while( index < count ); 99 95 return EOK; 100 96 } 101 97 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; 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; 121 108 } 122 109 }
Note:
See TracChangeset
for help on using the changeset viewer.