aboutsummaryrefslogtreecommitdiffstats
path: root/src/system
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-11-04 18:39:42 +0100
committerMax Kellermann <max@duempel.org>2013-11-04 19:13:05 +0100
commit7adfea8ca268162f10f9b1e1ec3a3322f14928a0 (patch)
tree7ea27a149b80c023668a2ecd463d4962edd7cd83 /src/system
parenteab1a776838815b4d7b1ac01cc7bcf5f56d3bfd9 (diff)
downloadmpd-7adfea8ca268162f10f9b1e1ec3a3322f14928a0.tar.gz
mpd-7adfea8ca268162f10f9b1e1ec3a3322f14928a0.tar.xz
mpd-7adfea8ca268162f10f9b1e1ec3a3322f14928a0.zip
system/resolver: return path of UNIX domain sockets
getnameinfo() doesn't work well - it always returns "localhost".
Diffstat (limited to 'src/system')
-rw-r--r--src/system/Resolver.cxx22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/system/Resolver.cxx b/src/system/Resolver.cxx
index 656de1349..5e6ea590b 100644
--- a/src/system/Resolver.cxx
+++ b/src/system/Resolver.cxx
@@ -32,6 +32,10 @@
#include <winsock.h>
#endif
+#ifdef HAVE_UN
+#include <sys/un.h>
+#endif
+
#include <string.h>
#include <stdio.h>
@@ -40,6 +44,17 @@ const Domain resolver_domain("resolver");
char *
sockaddr_to_string(const struct sockaddr *sa, size_t length, Error &error)
{
+#ifdef HAVE_UN
+ if (sa->sa_family == AF_UNIX) {
+ /* return path of UNIX domain sockets */
+ const sockaddr_un &s_un = *(const sockaddr_un *)sa;
+ if (length < sizeof(s_un) || s_un.sun_path[0] == 0)
+ return g_strdup("local");
+
+ return g_strdup(s_un.sun_path);
+ }
+#endif
+
#if defined(HAVE_IPV6) && defined(IN6_IS_ADDR_V4MAPPED)
const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)sa;
struct sockaddr_in a4;
@@ -70,13 +85,6 @@ sockaddr_to_string(const struct sockaddr *sa, size_t length, Error &error)
return NULL;
}
-#ifdef HAVE_UN
- if (sa->sa_family == AF_UNIX)
- /* "serv" contains corrupt information with unix
- sockets */
- return g_strdup(host);
-#endif
-
#ifdef HAVE_IPV6
if (strchr(host, ':') != NULL)
return g_strconcat("[", host, "]:", serv, NULL);