| 585 | } |
| 586 | |
| 587 | bool 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 |