diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | udp514-journal.c | 17 |
2 files changed, 9 insertions, 10 deletions
@@ -14,7 +14,7 @@ LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie # this is just a fallback in case you do not use git but downloaded # a release tarball... -VERSION := 0.2.0 +VERSION := 0.2.1 all: udp514-journal README.html diff --git a/udp514-journal.c b/udp514-journal.c index a518ca3..402785c 100644 --- a/udp514-journal.c +++ b/udp514-journal.c @@ -100,12 +100,16 @@ int main(int argc, char **argv) { /* get client's ip address */ switch (addr_client->sa_family) { case AF_INET6: - address = inet_ntop(AF_INET6, &addr_client_in6->sin6_addr, - addr_buf, INET6_ADDRSTRLEN); + const struct in6_addr *in6_addr = &addr_client_in6->sin6_addr; + address = inet_ntop(AF_INET6, in6_addr, addr_buf, INET6_ADDRSTRLEN); + /* strip prefix (::ffff:) from mapped ipv4 addresses */ + if (address && IN6_IS_ADDR_V4MAPPED(in6_addr)) { + address += 7; + } break; case AF_INET: - address = inet_ntop(AF_INET, &addr_client_in->sin_addr, - addr_buf, INET6_ADDRSTRLEN); + const struct in_addr *in_addr = &addr_client_in->sin_addr; + address = inet_ntop(AF_INET, in_addr, addr_buf, INET6_ADDRSTRLEN); break; default: fputs("unhadled address family", stderr); @@ -116,11 +120,6 @@ int main(int argc, char **argv) { continue; } - /* strip prefix from mapped ipv4 addresses */ - if (strncmp(address, "::ffff:", 7) == 0) { - address += 7; - } - /* send to systemd-journald */ sd_journal_send("MESSAGE=%s", msg_buf, "SYSLOG_IDENTIFIER=%s", address, |