| 528 | } |
| 529 | |
| 530 | const char *parse_wireaddr(const tal_t *ctx, |
| 531 | const char *arg, |
| 532 | u16 defport, |
| 533 | bool *no_dns, |
| 534 | struct wireaddr *addr) |
| 535 | { |
| 536 | struct in6_addr v6; |
| 537 | struct in_addr v4; |
| 538 | u16 port; |
| 539 | char *ip; |
| 540 | const char *err_msg; |
| 541 | struct wireaddr *addresses; |
| 542 | bool is_dns_waddr; |
| 543 | |
| 544 | port = defport; |
| 545 | |
| 546 | if (strstarts(arg, "dns:")) { |
| 547 | is_dns_waddr = true; |
| 548 | arg += 4; |
| 549 | } else |
| 550 | is_dns_waddr = false; |
| 551 | |
| 552 | if (!separate_address_and_port(tmpctx, arg, &ip, &port)) |
| 553 | return tal_strdup(ctx, "Error parsing hostname"); |
| 554 | |
| 555 | if (!is_dns_waddr) { |
| 556 | /* We resolved these even without DNS */ |
| 557 | if (streq(ip, "localhost")) |
| 558 | ip = "127.0.0.1"; |
| 559 | else if (streq(ip, "ip6-localhost")) |
| 560 | ip = "::1"; |
| 561 | } |
| 562 | |
| 563 | memset(&addr->addr, 0, sizeof(addr->addr)); |
| 564 | |
| 565 | if (inet_pton(AF_INET, ip, &v4) == 1) { |
| 566 | if (is_dns_waddr) |
| 567 | return tal_strdup(ctx, "dns: must be followed by a name"); |
| 568 | wireaddr_from_ipv4(addr, &v4, port); |
| 569 | return NULL; |
| 570 | } else if (inet_pton(AF_INET6, ip, &v6) == 1) { |
| 571 | if (is_dns_waddr) |
| 572 | return tal_strdup(ctx, "dns: must be followed by a name"); |
| 573 | wireaddr_from_ipv6(addr, &v6, port); |
| 574 | return NULL; |
| 575 | } |
| 576 | |
| 577 | if (is_dns_waddr) { |
| 578 | addr->type = ADDR_TYPE_DNS; |
| 579 | if (strlen(ip) > DNS_ADDRLEN) |
| 580 | return "DNS address too long"; |
| 581 | |
| 582 | /* fromwire_wireaddr() ignores a DNS descriptor which isn't a |
| 583 | * hostname, so anything we announce that fails this is dropped |
| 584 | * by every peer. Say so here, where the operator can see it. */ |
| 585 | if (!is_dnsaddr(ip)) |
| 586 | return tal_fmt(ctx, "dns: '%s' is not a hostname", ip); |
| 587 | |