wireaddr: fix ipv6 formatting with ports in fmt_wireaddr

Correctly format ipv6 address with ports. This will also make it more compatible
with the new parse_wireaddr, which has been updated to parse ports. They are
inverses now.

Also add some tests that check this.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2017-12-18 02:25:16 -08:00
committed by Rusty Russell
parent d89eb32c85
commit ce1d709d44
3 changed files with 36 additions and 2 deletions

View File

@@ -38,7 +38,7 @@ void towire_wireaddr(u8 **pptr, const struct wireaddr *addr)
towire_u16(pptr, addr->port);
}
static char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a)
char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a)
{
char addrstr[INET6_ADDRSTRLEN];
char *ret, *hex;
@@ -51,7 +51,7 @@ static char *fmt_wireaddr(const tal_t *ctx, const struct wireaddr *a)
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);
return tal_fmt(ctx, "[%s]:%u", addrstr, a->port);
case ADDR_TYPE_PADDING:
break;
}