aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/socket_util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/socket_util.c b/src/socket_util.c
index 240577fc6..31b656326 100644
--- a/src/socket_util.c
+++ b/src/socket_util.c
@@ -29,9 +29,29 @@
char *
sockaddr_to_string(const struct sockaddr *sa, size_t length, GError **error)
{
+#ifdef HAVE_IPV6
+ const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)sa;
+ struct sockaddr_in a4;
+#endif
int ret;
char host[NI_MAXHOST], serv[NI_MAXSERV];
+#ifdef HAVE_IPV6
+ if (sa->sa_family == AF_INET6 &&
+ IN6_IS_ADDR_V4MAPPED(&a6->sin6_addr)) {
+ /* convert "::ffff:127.0.0.1" to "127.0.0.1" */
+
+ memset(&a4, 0, sizeof(a4));
+ a4.sin_family = AF_INET;
+ memcpy(&a4.sin_addr, ((const char *)&a6->sin6_addr) + 12,
+ sizeof(a4.sin_addr));
+ a4.sin_port = a6->sin6_port;
+
+ sa = (const struct sockaddr *)&a4;
+ length = sizeof(a4);
+ }
+#endif
+
ret = getnameinfo(sa, length, host, sizeof(host), serv, sizeof(serv),
NI_NUMERICHOST|NI_NUMERICSERV);
if (ret != 0) {