diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-05-29 10:34:08 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-05-29 10:34:08 +0000 |
commit | 79c39ae0dcdce37ab750b257ad07786ef20f146e (patch) | |
tree | c82c65b14e5eef30b07e9a68a93d18e2900a068b | |
parent | efc10f0c4413f24c6bd9998e83ae2a919ec6d2be (diff) |
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@
-rw-r--r-- | usr.sbin/bgpd/util.c | 12 |
1 files 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 <claudio@openbsd.org> @@ -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 * |