From d4f319deafc41d000c7e249e1acfe9626dec52a8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 12 Apr 2008 04:07:18 +0000 Subject: support listening on unix domain sockets This trivial patch addresses bug 1639. When a bind_to_address argument starts with a slash, assume that it is the address of a Unix domain socket. git-svn-id: https://svn.musicpd.org/mpd/trunk@7235 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/listen.c | 16 ++++++++++++++++ src/os_compat.h | 1 + 2 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/listen.c b/src/listen.c index 78bb6ace1..423b54e9a 100644 --- a/src/listen.c +++ b/src/listen.c @@ -157,6 +157,22 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) #endif BINDERROR(); } + } else if (param->value[0] == '/') { + size_t path_length; + struct sockaddr_un sun; + + path_length = strlen(param->value); + if (path_length >= sizeof(sun.sun_path)) + FATAL("unix socket path is too long\n"); + + sun.sun_family = AF_UNIX; + memcpy(sun.sun_path, param->value, path_length + 1); + + addrp = (const struct sockaddr *)&sun; + addrlen = sizeof(sun); + + if (establishListen(addrp, addrlen) < 0) + BINDERROR(); } else { struct hostent *he; DEBUG("binding to address for %s\n", param->value); diff --git a/src/os_compat.h b/src/os_compat.h index c6268d0d8..6409053c7 100644 --- a/src/os_compat.h +++ b/src/os_compat.h @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3