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. */
| 306 | * it only overwrites *port if it was specified by <number> above. |
| 307 | */ |
| 308 | bool separate_address_and_port(const tal_t *ctx, const char *arg, |
| 309 | char **addr, u16 *port) |
| 310 | { |
| 311 | char *portcolon; |
| 312 | |
| 313 | if (strstarts(arg, "[")) { |
| 314 | char *end = strchr(arg, ']'); |
| 315 | if (!end) |
| 316 | return false; |
| 317 | /* Copy inside [] */ |
| 318 | *addr = tal_strndup(ctx, arg + 1, end - arg - 1); |
| 319 | portcolon = strchr(end+1, ':'); |
| 320 | } else { |
| 321 | portcolon = strchr(arg, ':'); |
| 322 | if (portcolon) { |
| 323 | /* Disregard if there's more than one : or if it's at |
| 324 | the end */ |
| 325 | if (portcolon != strrchr(arg, ':') |
| 326 | || portcolon[1] == '\0') |
| 327 | portcolon = NULL; |
| 328 | } |
| 329 | if (portcolon) |
| 330 | *addr = tal_strndup(ctx, arg, portcolon - arg); |
| 331 | else |
| 332 | *addr = tal_strdup(ctx, arg); |
| 333 | } |
| 334 | |
| 335 | if (portcolon) { |
| 336 | char *endp; |
| 337 | *port = strtol(portcolon + 1, &endp, 10); |
| 338 | return *port != 0 && *endp == '\0'; |
| 339 | } |
| 340 | |
| 341 | return true; |
| 342 | } |
| 343 | |
| 344 | bool is_ipaddr(const char *arg) |
| 345 | { |
no outgoing calls