| 505 | } |
| 506 | |
| 507 | bool parse_wireaddr(const char *arg, struct wireaddr *addr, u16 defport, |
| 508 | bool *no_dns, const char **err_msg) |
| 509 | { |
| 510 | struct in6_addr v6; |
| 511 | struct in_addr v4; |
| 512 | u16 port; |
| 513 | char *ip; |
| 514 | bool res; |
| 515 | |
| 516 | res = false; |
| 517 | port = defport; |
| 518 | if (err_msg) |
| 519 | *err_msg = NULL; |
| 520 | |
| 521 | if (!separate_address_and_port(tmpctx, arg, &ip, &port)) |
| 522 | goto finish; |
| 523 | |
| 524 | if (streq(ip, "localhost")) |
| 525 | ip = "127.0.0.1"; |
| 526 | else if (streq(ip, "ip6-localhost")) |
| 527 | ip = "::1"; |
| 528 | |
| 529 | memset(&addr->addr, 0, sizeof(addr->addr)); |
| 530 | |
| 531 | if (inet_pton(AF_INET, ip, &v4) == 1) { |
| 532 | wireaddr_from_ipv4(addr, &v4, port); |
| 533 | res = true; |
| 534 | } else if (inet_pton(AF_INET6, ip, &v6) == 1) { |
| 535 | wireaddr_from_ipv6(addr, &v6, port); |
| 536 | res = true; |
| 537 | } |
| 538 | |
| 539 | /* Resolve with getaddrinfo */ |
| 540 | if (!res) { |
| 541 | struct wireaddr *addresses = wireaddr_from_hostname(NULL, ip, port, |
| 542 | no_dns, NULL, err_msg); |
| 543 | if (addresses) { |
| 544 | *addr = addresses[0]; |
| 545 | tal_free(addresses); |
| 546 | res = true; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | finish: |
| 551 | if (!res && err_msg && !*err_msg) |
| 552 | *err_msg = "Error parsing hostname"; |
| 553 | return res; |
| 554 | } |
| 555 | |
| 556 | bool wireaddr_internal_eq(const struct wireaddr_internal *a, |
| 557 | const struct wireaddr_internal *b) |