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
This commit is contained in:
Max Kellermann 2008-04-12 04:07:18 +00:00 committed by Eric Wong
parent 623a86f389
commit d4f319deaf
2 changed files with 17 additions and 0 deletions

View File

@ -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);

View File

@ -64,6 +64,7 @@
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <pwd.h>
#include <grp.h>
#include <limits.h>