diff options
author | Corubba Smith <corubba@gmx.de> | 2025-02-16 15:03:51 +0100 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2025-03-11 16:15:29 +0100 |
commit | bebb752ce4d4d9d6bfedeb595fef8fdee42dd98a (patch) | |
tree | 8b126eb557867720795ba79a6d7b9d09a4ea037b | |
parent | 2d8b64ab788ea2fbe19de03a10b5f7e7237cff31 (diff) |
gprint: fix comma after ip addresses
Do the same as the oprint plugin: let inet_ntop() write to a temporary
buffer, and then write that buffer content and the trailing comma to the
actual output buffer in one go.
Fixes: f04bf6794d11 ("gprint, oprint: use inet_ntop to format ip addresses")
Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r-- | output/ulogd_output_GPRINT.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/output/ulogd_output_GPRINT.c b/output/ulogd_output_GPRINT.c index 37829fa..20dd308 100644 --- a/output/ulogd_output_GPRINT.c +++ b/output/ulogd_output_GPRINT.c @@ -155,6 +155,7 @@ static int gprint_interp(struct ulogd_pluginstance *upi) size += ret; break; case ULOGD_RET_IPADDR: { + char addrbuf[INET6_ADDRSTRLEN + 1] = ""; struct in6_addr ipv6addr; struct in_addr ipv4addr; int family; @@ -176,10 +177,12 @@ static int gprint_interp(struct ulogd_pluginstance *upi) addr = &ipv4addr; family = AF_INET; } - if (!inet_ntop(family, addr, buf + size, rem)) + if (!inet_ntop(family, addr, addrbuf, sizeof(addrbuf))) break; - ret = strlen(buf + size); + ret = snprintf(buf+size, rem, "%s,", addrbuf); + if (ret < 0) + break; rem -= ret; size += ret; break; |