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

Function parse_wireaddr

common/wireaddr.c:507–554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505}
506
507bool 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
550finish:
551 if (!res && err_msg && !*err_msg)
552 *err_msg = "Error parsing hostname";
553 return res;
554}
555
556bool wireaddr_internal_eq(const struct wireaddr_internal *a,
557 const struct wireaddr_internal *b)

Callers 7

make_onionFunction · 0.85
make_fixed_onionFunction · 0.85
mainFunction · 0.85
opt_add_proxy_addrFunction · 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