|
|
@ -106,37 +106,6 @@ bool fromwire_wireaddr_internal(const u8 **cursor, size_t *max, |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a) |
|
|
|
{ |
|
|
|
char addrstr[LARGEST_ADDRLEN]; |
|
|
|
char *ret, *hex; |
|
|
|
|
|
|
|
switch (a->type) { |
|
|
|
case ADDR_TYPE_IPV4: |
|
|
|
if (!inet_ntop(AF_INET, a->addr, addrstr, INET_ADDRSTRLEN)) |
|
|
|
return "Unprintable-ipv4-address"; |
|
|
|
return tal_fmt(ctx, "%s:%u", addrstr, a->port); |
|
|
|
case ADDR_TYPE_IPV6: |
|
|
|
if (!inet_ntop(AF_INET6, a->addr, addrstr, INET6_ADDRSTRLEN)) |
|
|
|
return "Unprintable-ipv6-address"; |
|
|
|
return tal_fmt(ctx, "[%s]:%u", addrstr, a->port); |
|
|
|
case ADDR_TYPE_TOR_V2: |
|
|
|
return tal_fmt(ctx, "%s.onion:%u", |
|
|
|
b32_encode(addrstr, (u8 *) a->addr, 2), a->port); |
|
|
|
case ADDR_TYPE_TOR_V3: |
|
|
|
return tal_fmt(ctx, "%s.onion:%u", |
|
|
|
b32_encode(addrstr, (u8 *) a->addr, 3), a->port); |
|
|
|
case ADDR_TYPE_PADDING: |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
hex = tal_hexstr(ctx, a->addr, a->addrlen); |
|
|
|
ret = tal_fmt(ctx, "Unknown type %u %s:%u", a->type, hex, a->port); |
|
|
|
tal_free(hex); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
REGISTER_TYPE_TO_STRING(wireaddr, fmt_wireaddr); |
|
|
|
|
|
|
|
void wireaddr_from_ipv4(struct wireaddr *addr, |
|
|
|
const struct in_addr *ip4, |
|
|
|
const u16 port) |
|
|
@ -240,6 +209,14 @@ char *fmt_wireaddr_without_port(const tal_t * ctx, const struct wireaddr *a) |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a) |
|
|
|
{ |
|
|
|
char *ret = fmt_wireaddr_without_port(ctx, a); |
|
|
|
tal_append_fmt(&ret, ":%u", a->port); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
REGISTER_TYPE_TO_STRING(wireaddr, fmt_wireaddr); |
|
|
|
|
|
|
|
/* Valid forms:
|
|
|
|
* |
|
|
|
* [anything]:<number> |
|
|
|