| 77 | } |
| 78 | |
| 79 | bool InetAddress::Parse( const std::string& address_string, InetAddress& out_address ) |
| 80 | { |
| 81 | unsigned char addr[4]; |
| 82 | |
| 83 | const char* str= address_string.c_str(); |
| 84 | for( unsigned int i= 0u; i < 4u; i++ ) |
| 85 | { |
| 86 | if( ! std::isdigit( *str ) ) return false; |
| 87 | |
| 88 | const int n= std::atoi(str); |
| 89 | if( ! ( n >= 0 && n <= 255 ) ) return false; |
| 90 | |
| 91 | addr[ 3u - i ]= static_cast<unsigned char>(n); |
| 92 | |
| 93 | while( std::isdigit( *str ) && *str != '\0' ) str++; |
| 94 | |
| 95 | if( i != 3u ) |
| 96 | { |
| 97 | if( *str != '.' ) return false; |
| 98 | str++; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | std::memcpy( &out_address.ip_address, &addr, 4u ); |
| 103 | out_address.port= 0u; |
| 104 | |
| 105 | if( *str == ':' ) |
| 106 | { |
| 107 | str++; |
| 108 | if( *str == '\0' ) return false; |
| 109 | if( ! std::isdigit( *str ) ) return false; |
| 110 | const int port= std::atoi( str ); |
| 111 | if( !( port > 0 && port < 65536 ) ) return false; |
| 112 | out_address.port= port; |
| 113 | } |
| 114 | |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | std::string InetAddress::ToString() const |
| 119 | { |
nothing calls this directly
no outgoing calls
no test coverage detected