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

Function parse_wireaddr

common/wireaddr.c:514–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

512}
513
514const char *parse_wireaddr(const tal_t *ctx,
515 const char *arg,
516 u16 defport,
517 bool *no_dns,
518 struct wireaddr *addr)
519{
520 struct in6_addr v6;
521 struct in_addr v4;
522 u16 port;
523 char *ip;
524 const char *err_msg;
525 struct wireaddr *addresses;
526 bool is_dns_waddr;
527
528 port = defport;
529
530 if (strstarts(arg, "dns:")) {
531 is_dns_waddr = true;
532 arg += 4;
533 } else
534 is_dns_waddr = false;
535
536 if (!separate_address_and_port(tmpctx, arg, &ip, &port))
537 return tal_strdup(ctx, "Error parsing hostname");
538
539 if (!is_dns_waddr) {
540 /* We resolved these even without DNS */
541 if (streq(ip, "localhost"))
542 ip = "127.0.0.1";
543 else if (streq(ip, "ip6-localhost"))
544 ip = "::1";
545 }
546
547 memset(&addr->addr, 0, sizeof(addr->addr));
548
549 if (inet_pton(AF_INET, ip, &v4) == 1) {
550 if (is_dns_waddr)
551 return tal_strdup(ctx, "dns: must be followed by a name");
552 wireaddr_from_ipv4(addr, &v4, port);
553 return NULL;
554 } else if (inet_pton(AF_INET6, ip, &v6) == 1) {
555 if (is_dns_waddr)
556 return tal_strdup(ctx, "dns: must be followed by a name");
557 wireaddr_from_ipv6(addr, &v6, port);
558 return NULL;
559 }
560
561 if (is_dns_waddr) {
562 addr->type = ADDR_TYPE_DNS;
563 if (strlen(ip) > DNS_ADDRLEN)
564 return "DNS address too long";
565
566 addr->addrlen = strlen(ip);
567 memcpy(addr->addr, ip, addr->addrlen);
568 addr->port = port;
569 return NULL;
570 }
571

Callers 8

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

Calls 5

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

Tested by 3

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68