From 9ad78aa8fb8ac54b768164bee1c19a5066d21472 Mon Sep 17 00:00:00 2001 From: claudio Date: Wed, 29 May 2024 10:34:07 +0000 Subject: [PATCH] Introduce a ring buffer for log_sockaddr() this way log_addr() can be used more then once in a log message (e.g. log_peer_warnx + log_addr. OK henning@ sthen@ --- usr.sbin/bgpd/util.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/usr.sbin/bgpd/util.c b/usr.sbin/bgpd/util.c index 44513b92945..c81d1431664 100644 --- a/usr.sbin/bgpd/util.c +++ b/usr.sbin/bgpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.85 2024/03/22 15:41:34 claudio Exp $ */ +/* $OpenBSD: util.c,v 1.86 2024/05/29 10:34:07 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker @@ -98,13 +98,15 @@ log_in6addr(const struct in6_addr *addr) const char * log_sockaddr(struct sockaddr *sa, socklen_t len) { - static char buf[NI_MAXHOST]; + static char buf[4][NI_MAXHOST]; + static int bufidx; - if (sa == NULL || getnameinfo(sa, len, buf, sizeof(buf), NULL, 0, - NI_NUMERICHOST)) + bufidx = (bufidx + 1) % 4; + if (sa == NULL || getnameinfo(sa, len, buf[bufidx], sizeof(buf[0]), + NULL, 0, NI_NUMERICHOST)) return ("(unknown)"); else - return (buf); + return (buf[bufidx]); } const char * -- 2.20.1