X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=libfcgi%2Fos_unix.c;h=7912c9b62f76d283391eeeb7bd3341a547d0d21c;hb=5215a48a265b9583234d1d3c105b0c1cfcf96d21;hp=a58c1f2c6642ac838e3916467ccbad737c0d2aad;hpb=62e100c72f5df33c59b94efd0e8eec80de2274d4;p=catagits%2Ffcgi2.git diff --git a/libfcgi/os_unix.c b/libfcgi/os_unix.c index a58c1f2..7912c9b 100755 --- a/libfcgi/os_unix.c +++ b/libfcgi/os_unix.c @@ -17,7 +17,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: os_unix.c,v 1.24 2001/03/27 14:03:20 robs Exp $"; +static const char rcsid[] = "$Id: os_unix.c,v 1.26 2001/06/18 14:24:28 robs Exp $"; #endif /* not lint */ #include "fcgi_config.h" @@ -60,12 +60,8 @@ static const char rcsid[] = "$Id: os_unix.c,v 1.24 2001/03/27 14:03:20 robs Exp #include "fcgimisc.h" #include "fcgios.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 +#ifndef INADDR_NONE +#define INADDR_NONE ((unsigned long) -1) #endif /* @@ -244,6 +240,7 @@ int OS_CreateLocalIpcFd(const char *bindPath, int backlog) int listenSock, servLen; union SockAddrUnion sa; int tcp = FALSE; + unsigned long tcp_ia; char *tp; short port; char host[MAXPATHLEN]; @@ -257,12 +254,26 @@ int OS_CreateLocalIpcFd(const char *bindPath, int backlog) tcp = TRUE; } } - if(tcp && (*host && strcmp(host, "localhost") != 0)) { - fprintf(stderr, "To start a service on a TCP port can not " - "specify a host name.\n" - "You should either use \"localhost:\" or " - " just use \":.\"\n"); - exit(1); + if(tcp) { + if (!*host || !strcmp(host,"*")) { + tcp_ia = htonl(INADDR_ANY); + } else { + tcp_ia = inet_addr(host); + if (tcp_ia == INADDR_NONE) { + struct hostent * hep; + hep = gethostbyname(host); + if ((!hep) || (hep->h_addrtype != AF_INET || !hep->h_addr_list[0])) { + fprintf(stderr, "Cannot resolve host name %s -- exiting!\n", host); + exit(1); + } + if (hep->h_addr_list[1]) { + fprintf(stderr, "Host %s has multiple addresses ---\n", host); + fprintf(stderr, "you must choose one explicitly!!!\n"); + exit(1); + } + tcp_ia = ((struct in_addr *) (hep->h_addr))->s_addr; + } + } } if(tcp) { @@ -288,7 +299,7 @@ int OS_CreateLocalIpcFd(const char *bindPath, int backlog) if(tcp) { memset((char *) &sa.inetVariant, 0, sizeof(sa.inetVariant)); sa.inetVariant.sin_family = AF_INET; - sa.inetVariant.sin_addr.s_addr = htonl(INADDR_ANY); + sa.inetVariant.sin_addr.s_addr = tcp_ia; sa.inetVariant.sin_port = htons(port); servLen = sizeof(sa.inetVariant); } else {