diff options
author | claudio <claudio@openbsd.org> | 2007-10-08 20:28:17 +0000 |
---|---|---|
committer | claudio <claudio@openbsd.org> | 2007-10-08 20:28:17 +0000 |
commit | 2e4f8691af500a954343a7446c3fcf27fbb0462b (patch) | |
tree | e09a4bd3d48de49563548e7daaba5d562246a012 /usr.sbin/ospf6d/log.c | |
parent | Align the suspend saved data to a cache line boundary, apparently prevents (diff) | |
download | wireguard-openbsd-2e4f8691af500a954343a7446c3fcf27fbb0462b.tar.xz wireguard-openbsd-2e4f8691af500a954343a7446c3fcf27fbb0462b.zip |
Use a small cyclic buffer ring in log_in6addr() so that the function can be
used more then once per printf. The current limit is 4.
Diffstat (limited to 'usr.sbin/ospf6d/log.c')
-rw-r--r-- | usr.sbin/ospf6d/log.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr.sbin/ospf6d/log.c b/usr.sbin/ospf6d/log.c index 911aed34235..98064b2ddab 100644 --- a/usr.sbin/ospf6d/log.c +++ b/usr.sbin/ospf6d/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.1 2007/10/08 10:44:50 norby Exp $ */ +/* $OpenBSD: log.c,v 1.2 2007/10/08 20:28:17 claudio Exp $ */ /* * Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org> @@ -192,16 +192,20 @@ log_in6addr(const struct in6_addr *addr) return (log_sockaddr((struct sockaddr *)&sa_in6)); } +#define NUM_LOGS 4 const char * log_sockaddr(struct sockaddr *sa) { - static char buf[NI_MAXHOST]; + static char buf[NUM_LOGS][NI_MAXHOST]; + static int round = 0; - if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), NULL, 0, + round = (round + 1) % NUM_LOGS; + + if (getnameinfo(sa, sa->sa_len, buf[round], NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) return ("(unknown)"); else - return (buf); + return (buf[round]); } /* names */ |