diff options
Diffstat (limited to 'udp514-journal.c')
-rw-r--r-- | udp514-journal.c | 17 |
1 files changed, 8 insertions, 9 deletions
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, |