| 636 | } |
| 637 | |
| 638 | const char *parse_wireaddr_internal(const tal_t *ctx, |
| 639 | const char *arg, |
| 640 | u16 default_port, |
| 641 | bool dns_lookup_ok, |
| 642 | struct wireaddr_internal *addr) |
| 643 | { |
| 644 | u16 splitport; |
| 645 | char *ip; |
| 646 | char *service_addr; |
| 647 | const char *err; |
| 648 | bool needed_dns, is_websocket; |
| 649 | |
| 650 | /* Addresses starting with '/' are local socket paths */ |
| 651 | if (arg[0] == '/') { |
| 652 | addr->itype = ADDR_INTERNAL_SOCKNAME; |
| 653 | |
| 654 | /* Check if the path is too long */ |
| 655 | if (strlen(arg) >= sizeof(addr->u.sockname)) |
| 656 | return "Socket name too long"; |
| 657 | |
| 658 | /* Zero it out for passing across the wire */ |
| 659 | memset(addr->u.sockname, 0, sizeof(addr->u.sockname)); |
| 660 | strcpy(addr->u.sockname, arg); |
| 661 | return NULL; |
| 662 | } |
| 663 | |
| 664 | /* 'autotor:' is a special prefix meaning talk to Tor to create |
| 665 | * an onion address. */ |
| 666 | if (strstarts(arg, "autotor:")) { |
| 667 | addr->itype = ADDR_INTERNAL_AUTOTOR; |
| 668 | addr->u.torservice.port = chainparams_get_ln_port(chainparams); |
| 669 | /* Format is separated by slash. */ |
| 670 | char **parts = tal_strsplit(tmpctx, arg, "/", STR_EMPTY_OK); |
| 671 | |
| 672 | for (size_t i = 1; i < tal_count(parts)-1; i++) { |
| 673 | if (strstarts(parts[i], "torport=")) { |
| 674 | char *endp = NULL; |
| 675 | addr->u.torservice.port = strtol(parts[i]+strlen("torport="), &endp, 10); |
| 676 | if (addr->u.torservice.port <= 0 || *endp != '\0') { |
| 677 | return "Bad :torport: number"; |
| 678 | } |
| 679 | } else { |
| 680 | return tal_fmt(ctx, "unknown tor arg %s", parts[i]); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | service_addr = tal_fmt(tmpctx, "%s", parts[0] + strlen("autotor:")); |
| 685 | return parse_wireaddr(ctx, service_addr, 9051, |
| 686 | dns_lookup_ok ? NULL : &needed_dns, |
| 687 | &addr->u.torservice.address); |
| 688 | } |
| 689 | |
| 690 | /* 'statictor:' is a special prefix meaning talk to Tor to create |
| 691 | * an static onion address from a blob or node id */ |
| 692 | if (strstarts(arg, "statictor:")) { |
| 693 | bool use_magic_blob = true; |
| 694 | addr->itype = ADDR_INTERNAL_STATICTOR; |
| 695 | addr->u.torservice.port = chainparams_get_ln_port(chainparams); |