64 host (other.host), |
64 host (other.host), |
65 port (other.port) {} |
65 port (other.port) {} |
66 |
66 |
67 // ----------------------------------------------------------------------------- |
67 // ----------------------------------------------------------------------------- |
68 // |
68 // |
69 String IPAddress::to_string (WithPort withport) const |
69 std::string IPAddress::to_string (WithPort withport) const |
70 { |
70 { |
71 String val; |
71 std::string val; |
72 |
72 |
73 if (withport == WITH_PORT) |
73 if (withport == WITH_PORT) |
74 val = sprintf ("%u.%u.%u.%u:%u", octet (0), octet (1), octet (2), octet (3), port); |
74 val = sprintf ("%u.%u.%u.%u:%u", octet (0), octet (1), octet (2), octet (3), port); |
75 else |
75 else |
76 val = sprintf ("%u.%u.%u.%u", octet (0), octet (1), octet (2), octet (3)); |
76 val = sprintf ("%u.%u.%u.%u", octet (0), octet (1), octet (2), octet (3)); |
139 return claddr; |
139 return claddr; |
140 } |
140 } |
141 |
141 |
142 // ----------------------------------------------------------------------------- |
142 // ----------------------------------------------------------------------------- |
143 // |
143 // |
144 IPAddress IPAddress::from_string (String input) |
144 IPAddress IPAddress::from_string (std::string input) |
145 { |
145 { |
146 unsigned int parts[4]; |
146 unsigned int parts[4]; |
147 int colonpos = input.find (":"); |
147 int colonpos = input.find (":"); |
148 String addressString = colonpos == -1 ? input : mid(input, 0, colonpos); |
148 std::string addressString = colonpos == -1 ? input : mid(input, 0, colonpos); |
149 IPAddress value; |
149 IPAddress value; |
150 |
150 |
151 // Try scanf the IPv4 host first |
151 // Try scanf the IPv4 host first |
152 if (sscanf(addressString.data(), "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) |
152 if (sscanf(addressString.data(), "%u.%u.%u.%u", &parts[0], &parts[1], &parts[2], &parts[3])) |
153 { |
153 { |
172 return value; |
172 return value; |
173 } |
173 } |
174 |
174 |
175 // ----------------------------------------------------------------------------- |
175 // ----------------------------------------------------------------------------- |
176 // |
176 // |
177 IPAddress IPAddress::resolve (String node) |
177 IPAddress IPAddress::resolve (std::string node) |
178 { |
178 { |
179 AddrInfo hints; |
179 AddrInfo hints; |
180 AddrInfo* lookup; |
180 AddrInfo* lookup; |
181 memset (&hints, 0, sizeof hints); |
181 memset (&hints, 0, sizeof hints); |
182 hints.ai_family = AF_INET; |
182 hints.ai_family = AF_INET; |