| 265 | } |
| 266 | |
| 267 | int str2endpoint(const char* str, EndPoint* point) { |
| 268 | if (ExtendedEndPoint::create(str, point)) { |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | // Should be enough to hold ip address |
| 273 | char buf[64]; |
| 274 | size_t i = 0; |
| 275 | for (; i < sizeof(buf) && str[i] != '\0' && str[i] != ':'; ++i) { |
| 276 | buf[i] = str[i]; |
| 277 | } |
| 278 | if (i >= sizeof(buf) || str[i] != ':') { |
| 279 | return -1; |
| 280 | } |
| 281 | buf[i] = '\0'; |
| 282 | if (str2ip(buf, &point->ip) != 0) { |
| 283 | return -1; |
| 284 | } |
| 285 | ++i; |
| 286 | char* end = NULL; |
| 287 | point->port = strtol(str + i, &end, 10); |
| 288 | if (end == str + i) { |
| 289 | return -1; |
| 290 | } else if (*end) { |
| 291 | for (; isspace(*end); ++end); |
| 292 | if (*end) { |
| 293 | return -1; |
| 294 | } |
| 295 | } |
| 296 | if (point->port < 0 || point->port > 65535) { |
| 297 | return -1; |
| 298 | } |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | int str2endpoint(const char* ip_str, int port, EndPoint* point) { |
| 303 | if (ExtendedEndPoint::create(ip_str, port, point)) { |