MCPcopy Create free account
hub / github.com/ElementsProject/lightning / parse_wireaddr

Function parse_wireaddr

common/wireaddr.c:530–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530const 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

Callers 9

make_onionFunction · 0.85
make_fixed_onionFunction · 0.85
mainFunction · 0.85
opt_add_proxy_addrFunction · 0.85
json_connectFunction · 0.85
runFunction · 0.85
parse_wireaddr_internalFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 6

wireaddr_from_ipv4Function · 0.85
wireaddr_from_ipv6Function · 0.85
is_dnsaddrFunction · 0.85
wireaddr_from_hostnameFunction · 0.85
tal_freeFunction · 0.85

Tested by 3

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68