aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2009-03-29 16:51:02 +0000
committerStefan Bühler <stbuehler@web.de>2009-03-29 16:51:02 +0000
commit2d155d6ce3773431e57e37b433f54576cb13ea88 (patch)
tree58786c7ea6232a6cdc258bcf41d4344b0b2f6d74
parentc8783afea3904a31b4bd18ad641b3c6e3fe0a7dd (diff)
downloadspawn-fcgi-2d155d6ce3773431e57e37b433f54576cb13ea88.tar.gz
spawn-fcgi-2d155d6ce3773431e57e37b433f54576cb13ea88.zip
Add IPv6 support
git-svn-id: svn://svn.lighttpd.net/spawn-fcgi/trunk@41 4a9f3682-ca7b-49a8-9a55-ba4640e46f83
-rw-r--r--NEWS1
-rw-r--r--configure.ac26
-rw-r--r--spawn-fcgi.12
-rw-r--r--src/CMakeLists.txt11
-rw-r--r--src/config.h.cmake3
-rw-r--r--src/spawn-fcgi.c45
6 files changed, 79 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 10776b3..2ec82d6 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ NEWS
- 1.6.2 -
* Add homepage to README
+ * Add IPv6 support
- 1.6.1 - 2009-03-29
diff --git a/configure.ac b/configure.ac
index ed24561..f23a7ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,7 +37,31 @@ AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
-AC_CHECK_FUNCS([dup2 memset putenv select socket strerror strtol issetugid])
+AC_CHECK_FUNCS([dup2 memset putenv select socket strerror strtol issetugid inet_pton])
+
+
+dnl Check for IPv6 support
+
+AC_ARG_ENABLE(ipv6,
+ AC_HELP_STRING([--disable-ipv6],[disable IPv6 support]),
+ [case "${enableval}" in
+ yes) ipv6=true ;;
+ no) ipv6=false ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-ipv6) ;;
+ esac],[ipv6=true])
+
+if test x$ipv6 = xtrue; then
+ AC_CACHE_CHECK([for IPv6 support], ac_cv_ipv6_support,
+ [AC_TRY_LINK([ #include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>], [struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0; ],
+ [ac_cv_ipv6_support=yes], [ac_cv_ipv6_support=no])])
+
+ if test "$ac_cv_ipv6_support" = yes; then
+ AC_DEFINE(HAVE_IPV6,1,[Whether to enable IPv6 support])
+ fi
+fi
+
# check for extra compiler options (warning options)
if test "${GCC}" = "yes"; then
diff --git a/spawn-fcgi.1 b/spawn-fcgi.1
index 6919541..029dd04 100644
--- a/spawn-fcgi.1
+++ b/spawn-fcgi.1
@@ -50,7 +50,7 @@ This option is ignored if fcgiapp is given.
Change the current directory before spawning the application.
.TP 8
.B \-a <address>
-IP address to bind to; only used if \-p is given too.
+IPv4/IPv6 address to bind to; only used if \-p is given too. Defaults to "0.0.0.0" (IPv4).
.TP 8
.B \-p <port>
TCP port to bind to; you cannot combine this with the \-s option.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2bb0c95..5f2f0ff 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -40,6 +40,17 @@ CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(winsock2.h HAVE_WINSOCK2_H)
CHECK_FUNCTION_EXISTS(issetugid HAVE_ISSETUGID)
+CHECK_FUNCTION_EXISTS(inet_pton HAVE_INET_PTON)
+
+CHECK_C_SOURCE_COMPILES("
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+
+ int main() {
+ struct sockaddr_in6 s; struct in6_addr t=in6addr_any; int i=AF_INET6; s; t.s6_addr[0] = 0;
+ return 0;
+ }" HAVE_IPV6)
SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
CHECK_TYPE_SIZE(socklen_t HAVE_SOCKLEN_T)
diff --git a/src/config.h.cmake b/src/config.h.cmake
index 74a41bd..dd1ca06 100644
--- a/src/config.h.cmake
+++ b/src/config.h.cmake
@@ -32,3 +32,6 @@
#cmakedefine HAVE_SOCKLEN_T
#cmakedefine HAVE_ISSETUGID
+#cmakedefine HAVE_INET_PTON
+
+#cmakedefine HAVE_IPV6
diff --git a/src/spawn-fcgi.c b/src/spawn-fcgi.c
index e1ae704..cf999af 100644
--- a/src/spawn-fcgi.c
+++ b/src/spawn-fcgi.c
@@ -65,11 +65,18 @@ static int issetugid() {
}
#endif
+#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
+# define USE_IPV6
+#endif
+
static int bind_socket(const char *addr, unsigned short port, const char *unixsocket, uid_t uid, gid_t gid, int mode) {
int fcgi_fd, socket_type, val;
struct sockaddr_un fcgi_addr_un;
struct sockaddr_in fcgi_addr_in;
+#ifdef USE_IPV6
+ struct sockaddr_in6 fcgi_addr_in6;
+#endif
struct sockaddr *fcgi_addr;
socklen_t servlen;
@@ -118,16 +125,40 @@ static int bind_socket(const char *addr, unsigned short port, const char *unixso
} else {
memset(&fcgi_addr_in, 0, sizeof(fcgi_addr_in));
fcgi_addr_in.sin_family = AF_INET;
- if (addr != NULL) {
- fcgi_addr_in.sin_addr.s_addr = inet_addr(addr);
- } else {
- fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
- }
fcgi_addr_in.sin_port = htons(port);
- servlen = sizeof(fcgi_addr_in);
+ servlen = sizeof(fcgi_addr_in);
socket_type = AF_INET;
fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
+
+#ifdef USE_IPV6
+ memset(&fcgi_addr_in6, 0, sizeof(fcgi_addr_in6));
+ fcgi_addr_in6.sin6_family = AF_INET6;
+ fcgi_addr_in6.sin6_port = fcgi_addr_in.sin_port;
+#endif
+
+ if (addr == NULL) {
+ fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
+#ifdef HAVE_INET_PTON
+ } else if (1 == inet_pton(AF_INET, addr, &fcgi_addr_in.sin_addr)) {
+ /* nothing to do */
+#ifdef HAVE_IPV6
+ } else if (1 == inet_pton(AF_INET6, addr, &fcgi_addr_in6.sin6_addr)) {
+ servlen = sizeof(fcgi_addr_in6);
+ socket_type = AF_INET6;
+ fcgi_addr = (struct sockaddr *) &fcgi_addr_in6;
+#endif
+ } else {
+ fprintf(stderr, "spawn-fcgi: '%s' is not a valid IP address\n", addr);
+ return -1;
+#else
+ } else {
+ if ((in_addr_t)(-1) == (fcgi_addr_in.sin_addr.s_addr = inet_addr(addr))) {
+ fprintf(stderr, "spawn-fcgi: '%s' is not a valid IPv4 address\n", addr);
+ return -1;
+ }
+#endif
+ }
}
@@ -379,7 +410,7 @@ static void show_help () {
"Options:\n" \
" -f <path> filename of the fcgi-application (ignored if <fcgiapp> is given)\n" \
" -d <directory> chdir to directory before spawning\n" \
-" -a <address> bind to IP address\n" \
+" -a <address> bind to IPv4/IPv6 address (defaults to 0.0.0.0)\n" \
" -p <port> bind to TCP-port\n" \
" -s <path> bind to Unix domain socket\n" \
" -M <mode> change Unix domain socket mode\n" \