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

Function parse_wireaddr_internal

common/wireaddr.c:587–729  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

585}
586
587bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr,
588 u16 port, bool wildcard_ok, bool dns_ok,
589 bool unresolved_ok,
590 const char **err_msg)
591{
592 u16 splitport;
593 char *ip = NULL;
594 char *service_addr;
595 bool needed_dns = false;
596
597 /* Addresses starting with '/' are local socket paths */
598 if (arg[0] == '/') {
599 addr->itype = ADDR_INTERNAL_SOCKNAME;
600
601 /* Check if the path is too long */
602 if (strlen(arg) >= sizeof(addr->u.sockname)) {
603 if (err_msg)
604 *err_msg = "Socket name too long";
605 return false;
606 }
607 /* Zero it out for passing across the wire */
608 memset(addr->u.sockname, 0, sizeof(addr->u.sockname));
609 strcpy(addr->u.sockname, arg);
610 return true;
611 }
612
613 /* 'autotor:' is a special prefix meaning talk to Tor to create
614 * an onion address. */
615 if (strstarts(arg, "autotor:")) {
616 addr->itype = ADDR_INTERNAL_AUTOTOR;
617 addr->u.torservice.port = chainparams_get_ln_port(chainparams);
618 /* Format is separated by slash. */
619 char **parts = tal_strsplit(tmpctx, arg, "/", STR_EMPTY_OK);
620
621 for (size_t i = 1; i < tal_count(parts)-1; i++) {
622 if (strstarts(parts[i], "torport=")) {
623 char *endp = NULL;
624 addr->u.torservice.port = strtol(parts[i]+strlen("torport="), &endp, 10);
625 if (addr->u.torservice.port <= 0 || *endp != '\0') {
626 if (err_msg)
627 *err_msg = "Bad :torport: number";
628 return false;
629 }
630 } else {
631 if (err_msg)
632 *err_msg = tal_fmt(tmpctx, "unknown tor arg %s", parts[i]);
633 return false;
634 }
635 }
636
637 service_addr = tal_fmt(tmpctx, "%s", parts[0] + strlen("autotor:"));
638
639 return parse_wireaddr(service_addr,
640 &addr->u.torservice.address, 9051,
641 dns_ok ? NULL : &needed_dns, err_msg);
642 }
643
644 /* 'statictor:' is a special prefix meaning talk to Tor to create

Callers 11

wallet_peer_loadFunction · 0.85
test_wallet_outputsFunction · 0.85
test_channel_crudFunction · 0.85
opt_add_addr_withtypeFunction · 0.85
opt_add_addrFunction · 0.85
opt_add_bind_addrFunction · 0.85
json_connectFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 5

parse_wireaddrFunction · 0.85
is_wildcardaddrFunction · 0.85
wireaddr_from_unresolvedFunction · 0.85
chainparams_get_ln_portFunction · 0.50

Tested by 5

test_wallet_outputsFunction · 0.68
test_channel_crudFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68