mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
committed by
Rusty Russell
parent
d89eb32c85
commit
ce1d709d44
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user