From: Steinar H. Gunderson Date: Thu, 18 Apr 2013 23:27:24 +0000 (+0200) Subject: Show IPv4 clients by their IPv4 address instead of with a v4-mapped address. X-Git-Tag: 1.0.0~75 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=00ce9b4b703afd1d718acc8fc9c7f9f5c194a769;ds=sidebyside Show IPv4 clients by their IPv4 address instead of with a v4-mapped address. --- diff --git a/client.cpp b/client.cpp index 28e1f06..0c38a44 100644 --- a/client.cpp +++ b/client.cpp @@ -32,8 +32,19 @@ Client::Client(int sock) if (getpeername(sock, reinterpret_cast(&addr), &addr_len) == -1) { log_perror("getpeername"); remote_addr = ""; + return; + } + + char buf[INET6_ADDRSTRLEN]; + if (IN6_IS_ADDR_V4MAPPED(&addr.sin6_addr)) { + // IPv4 address, really. + if (inet_ntop(AF_INET, &addr.sin6_addr.s6_addr32[3], buf, sizeof(buf)) == NULL) { + log_perror("inet_ntop"); + remote_addr = ""; + } else { + remote_addr = buf; + } } else { - char buf[INET6_ADDRSTRLEN]; if (inet_ntop(addr.sin6_family, &addr.sin6_addr, buf, sizeof(buf)) == NULL) { log_perror("inet_ntop"); remote_addr = "";