Valid forms: * * [anything]: * anything-without-colons-or-left-brace: * anything-without-colons * string-with-multiple-colons * * Returns false if it wasn't one of these forms. If it returns true, * it only overwrites *port if it was specified by above. */
| 301 | * it only overwrites *port if it was specified by <number> above. |
| 302 | */ |
| 303 | bool separate_address_and_port(const tal_t *ctx, const char *arg, |
| 304 | char **addr, u16 *port) |
| 305 | { |
| 306 | const char *portcolon; |
| 307 | |
| 308 | if (strstarts(arg, "[")) { |
| 309 | const char *end = strchr(arg, ']'); |
| 310 | if (!end) |
| 311 | return false; |
| 312 | /* Copy inside [] */ |
| 313 | *addr = tal_strndup(ctx, arg + 1, end - arg - 1); |
| 314 | portcolon = strchr(end+1, ':'); |
| 315 | } else { |
| 316 | portcolon = strchr(arg, ':'); |
| 317 | if (portcolon) { |
| 318 | /* Disregard if there's more than one : or if it's at |
| 319 | the end */ |
| 320 | if (portcolon != strrchr(arg, ':') |
| 321 | || portcolon[1] == '\0') |
| 322 | portcolon = NULL; |
| 323 | } |
| 324 | if (portcolon) |
| 325 | *addr = tal_strndup(ctx, arg, portcolon - arg); |
| 326 | else |
| 327 | *addr = tal_strdup(ctx, arg); |
| 328 | } |
| 329 | |
| 330 | if (portcolon) { |
| 331 | char *endp; |
| 332 | *port = strtol(portcolon + 1, &endp, 10); |
| 333 | return *port != 0 && *endp == '\0'; |
| 334 | } |
| 335 | |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | bool is_ipaddr(const char *arg) |
| 340 | { |
no outgoing calls