diff options
author | Jan Kneschke <jan@kneschke.de> | 2005-11-23 10:46:21 +0000 |
---|---|---|
committer | Jan Kneschke <jan@kneschke.de> | 2005-11-23 10:46:21 +0000 |
commit | 96ae6c33150571ff4488b11f19eb697d8597e365 (patch) | |
tree | bd15167d508cedd6993b279a24746e5efb014ecf /src | |
parent | 0b97fea80d50b3960930b64a9eef5f30405d0992 (diff) | |
download | lighttpd-git-96ae6c33150571ff4488b11f19eb697d8597e365.tar.gz |
allow to bind the server to a unix-domain socket
git-svn-id: svn+ssh://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@878 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src')
-rw-r--r-- | src/base.h | 3 | ||||
-rw-r--r-- | src/network.c | 38 |
2 files changed, 38 insertions, 3 deletions
@@ -124,6 +124,9 @@ typedef union { struct sockaddr_in6 ipv6; #endif struct sockaddr_in ipv4; +#ifdef HAVE_SYS_UN_H + struct sockaddr_un un; +#endif struct sockaddr plain; } sock_addr; diff --git a/src/network.c b/src/network.c index 22a502cc..40e9bbae 100644 --- a/src/network.c +++ b/src/network.c @@ -70,6 +70,7 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) { unsigned int port = 0; const char *host; buffer *b; + int is_unix_domain_socket = 0; #ifdef SO_ACCEPTFILTER struct accept_filter_arg afa; @@ -121,15 +122,34 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) { *(sp++) = '\0'; port = strtol(sp, NULL, 10); - - if (port == 0 || port > 65535) { + + if (host[0] == '/') { + /* host is a unix-domain-socket */ + is_unix_domain_socket = 1; + } else if (port == 0 || port > 65535) { log_error_write(srv, __FILE__, __LINE__, "sd", "port out of range:", port); return -1; } if (*host == '\0') host = NULL; - + + if (is_unix_domain_socket) { +#ifdef HAVE_SYS_UN_H + + srv_socket->addr.plain.sa_family = AF_UNIX; + + if (-1 == (srv_socket->fd = socket(srv_socket->addr.plain.sa_family, SOCK_STREAM, 0))) { + log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno)); + return -1; + } +#else + log_error_write(srv, __FILE__, __LINE__, "s", + "ERROR: Unix Domain sockets are not supported."); + return -1; +#endif + } + #ifdef HAVE_IPV6 if (s->use_ipv6) { srv_socket->addr.plain.sa_family = AF_INET6; @@ -223,6 +243,18 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) { addr_len = sizeof(struct sockaddr_in); break; + case AF_UNIX: + srv_socket->addr.un.sun_family = AF_UNIX; + strcpy(srv_socket->addr.un.sun_path, host); + +#ifdef SUN_LEN + addr_len = SUN_LEN(&srv_socket->addr.un); +#else + /* stevens says: */ + addr_len = strlen(host) + sizeof(srv_socket->addr.un.sun_family); +#endif + + break; default: addr_len = 0; |