Browse Source

Add IPv6 support

git-svn-id: svn://svn.lighttpd.net/spawn-fcgi/trunk@41 4a9f3682-ca7b-49a8-9a55-ba4640e46f83
master
Stefan Bühler 13 years ago
parent
commit
2d155d6ce3
  1. 1
      NEWS
  2. 26
      configure.ac
  3. 2
      spawn-fcgi.1
  4. 11
      src/CMakeLists.txt
  5. 3
      src/config.h.cmake
  6. 45
      src/spawn-fcgi.c

1
NEWS

@ -5,6 +5,7 @@ NEWS
- 1.6.2 -
* Add homepage to README
* Add IPv6 support
- 1.6.1 - 2009-03-29

26
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

2
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.

11
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)

3
src/config.h.cmake

@ -32,3 +32,6 @@
#cmakedefine HAVE_SOCKLEN_T
#cmakedefine HAVE_ISSETUGID
#cmakedefine HAVE_INET_PTON
#cmakedefine HAVE_IPV6

45
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" \

Loading…
Cancel
Save