Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> --- output/ulogd_output_GPRINT.c | 16 ++++++++++++++-- output/ulogd_output_OPRINT.c | 21 ++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/output/ulogd_output_GPRINT.c b/output/ulogd_output_GPRINT.c index 093d3ea2b254..37829fa49e9d 100644 --- a/output/ulogd_output_GPRINT.c +++ b/output/ulogd_output_GPRINT.c @@ -155,7 +155,10 @@ static int gprint_interp(struct ulogd_pluginstance *upi) size += ret; break; case ULOGD_RET_IPADDR: { + struct in6_addr ipv6addr; struct in_addr ipv4addr; + int family; + void *addr; ret = snprintf(buf+size, rem, "%s=", key->name); if (ret < 0) @@ -163,8 +166,17 @@ static int gprint_interp(struct ulogd_pluginstance *upi) rem -= ret; size += ret; - ipv4addr.s_addr = key->u.value.ui32; - if (!inet_ntop(AF_INET, &ipv4addr, buf + size, rem)) + if (key->len == sizeof(ipv6addr)) { + memcpy(ipv6addr.s6_addr, key->u.value.ui128, + sizeof(ipv6addr.s6_addr)); + addr = &ipv6addr; + family = AF_INET6; + } else { + ipv4addr.s_addr = key->u.value.ui32; + addr = &ipv4addr; + family = AF_INET; + } + if (!inet_ntop(family, addr, buf + size, rem)) break; ret = strlen(buf + size); diff --git a/output/ulogd_output_OPRINT.c b/output/ulogd_output_OPRINT.c index b5586e850aa4..13934ff19efb 100644 --- a/output/ulogd_output_OPRINT.c +++ b/output/ulogd_output_OPRINT.c @@ -76,12 +76,23 @@ static int oprint_interp(struct ulogd_pluginstance *upi) fprintf(opi->of, "%" PRIu64 "\n", ret->u.value.ui64); break; case ULOGD_RET_IPADDR: { - char addrbuf[INET_ADDRSTRLEN + 1] = ""; + char addrbuf[INET6_ADDRSTRLEN + 1] = ""; + struct in6_addr ipv6addr; struct in_addr ipv4addr; - - ipv4addr.s_addr = ret->u.value.ui32; - if (!inet_ntop(AF_INET, &ipv4addr, addrbuf, - sizeof(addrbuf))) + int family; + void *addr; + + if (ret->len == sizeof(ipv6addr)) { + memcpy(ipv6addr.s6_addr, ret->u.value.ui128, + sizeof(ipv6addr.s6_addr)); + addr = &ipv6addr; + family = AF_INET6; + } else { + ipv4addr.s_addr = ret->u.value.ui32; + addr = &ipv4addr; + family = AF_INET; + } + if (!inet_ntop(family, addr, addrbuf, sizeof(addrbuf))) break; fprintf(opi->of, "%s\n", addrbuf); -- 2.40.1