summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2024-07-01 14:15:16 +0000
committerYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2024-07-01 14:15:16 +0000
commitf1bc758bf3a43641dcc642af43bf5ec5e833e519 (patch)
tree634de05e3eb6b3dc6d3b0480d9ae2e3f32655c80 /sbin
parent8b90154fb59eac9250acd023f91537fa1542c6f8 (diff)
Enclose IPv6 address in a square bracket if the address is used with
the port number. ok florian tobhe
Diffstat (limited to 'sbin')
-rw-r--r--sbin/iked/util.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/sbin/iked/util.c b/sbin/iked/util.c
index 2cd34d12b7c..5d987eb66ca 100644
--- a/sbin/iked/util.c
+++ b/sbin/iked/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.44 2024/02/03 00:38:08 jsg Exp $ */
+/* $OpenBSD: util.c,v 1.45 2024/07/01 14:15:15 yasuoka Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -644,16 +644,16 @@ prefixlen2mask6(uint8_t prefixlen, uint32_t *mask)
const char *
print_addr(void *addr)
{
- static char sbuf[IKED_CYCLE_BUFFERS][NI_MAXHOST + 7];
+ static char sbuf[IKED_CYCLE_BUFFERS][NI_MAXHOST + 9];
static int idx;
struct sockaddr *sa = addr;
- char *buf;
- size_t len;
+ char *buf, *hbuf;
+ size_t len, hlen;
char pbuf[7];
in_port_t port;
- buf = sbuf[idx];
- len = sizeof(sbuf[idx]);
+ hbuf = buf = sbuf[idx];
+ hlen = len = sizeof(sbuf[idx]);
if (++idx >= IKED_CYCLE_BUFFERS)
idx = 0;
@@ -662,13 +662,21 @@ print_addr(void *addr)
return (buf);
}
+ if ((port = socket_getport(sa)) != 0 && sa->sa_family == AF_INET6) {
+ /* surround [] */
+ *(hbuf++) = '[';
+ hlen--;
+ }
+
if (getnameinfo(sa, sa->sa_len,
- buf, len, NULL, 0, NI_NUMERICHOST) != 0) {
+ hbuf, hlen, NULL, 0, NI_NUMERICHOST) != 0) {
strlcpy(buf, "unknown", len);
return (buf);
}
- if ((port = socket_getport(sa)) != 0) {
+ if (port != 0) {
+ if (sa->sa_family == AF_INET6)
+ (void)strlcat(buf, "]", len);
snprintf(pbuf, sizeof(pbuf), ":%d", port);
(void)strlcat(buf, pbuf, len);
}