From: Art Cancro Date: Thu, 24 Jun 2004 14:50:35 +0000 (+0000) Subject: * Added the ability to listen on a single IP address instead of all addresses. X-Git-Tag: v7.86~5371 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=69d49e1ebf84e57c5b1c1b16a98cf95c60d2d72b * Added the ability to listen on a single IP address instead of all addresses. --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 9a8d4fc27..efb81c339 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 522.3 2004/06/24 14:50:35 ajc +* Added the ability to listen on a single IP address instead of all addresses. + Revision 522.2 2004/06/22 02:21:56 ajc * Minor UI tweaks @@ -1922,3 +1925,4 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/README.txt b/webcit/README.txt index 4cf5ed2ee..6151b7175 100644 --- a/webcit/README.txt +++ b/webcit/README.txt @@ -67,16 +67,23 @@ something like this: Several command-line options are also available. Here's the usage for the "webserver" program: - webserver [-p http_port] [-s] [-t tracefile] [-c] [remotehost [remoteport]] + webserver [-i ip_addr] [-p http_port] [-s] [-t tracefile] + [-c] [remotehost [remoteport]] *or* - webserver [-p http_port] [-s] [-t tracefile] [-c] uds /your/citadel/directory + webserver [-i ip_addr] [-p http_port] [-s] [-t tracefile] + [-c] uds /your/citadel/directory Explained: + -> ip_addr: the IP address on which you wish your WebCit server to run. + You can leave this out, in which case WebCit will listen on all + available network interfaces. Normally this will be the case, but if + you are running multiple Citadel systems on one host, it can be useful. + -> http_port: the TCP port on which you wish your WebCit server to run. - this can be any port number at all; there is no standard. Naturally, + This can be any port number at all; there is no standard. Naturally, you'll want to create a link to this port on your system's regular web pages (presumably on an Apache server running on port 80). Or, if you are installing WebCit on a dedicated server, then you might choose to diff --git a/webcit/webserver.c b/webcit/webserver.c index 63d903024..e6c7e45f3 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -28,6 +28,7 @@ #include #endif #include +#include #include #include #include @@ -61,14 +62,23 @@ char *ctdlport = DEFAULT_PORT; * This is a generic function to set up a master socket for listening on * a TCP port. The server shuts down if the bind fails. */ -int ig_tcp_server(int port_number, int queue_len) +int ig_tcp_server(char *ip_addr, int port_number, int queue_len) { struct sockaddr_in sin; int s, i; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; + if (ip_addr == NULL) { + sin.sin_addr.s_addr = INADDR_ANY; + } + else { + sin.sin_addr.s_addr = inet_addr(ip_addr); + } + + if (sin.sin_addr.s_addr == INADDR_NONE) { + sin.sin_addr.s_addr = INADDR_ANY; + } if (port_number == 0) { lprintf(1, "Cannot start: no port number specified.\n"); @@ -247,14 +257,18 @@ int main(int argc, char **argv) int a, i; /* General-purpose variables */ int port = PORT_NUM; /* Port to listen on */ char tracefile[PATH_MAX]; + char ip_addr[256]; /* Parse command line */ #ifdef HAVE_OPENSSL - while ((a = getopt(argc, argv, "hp:t:cs")) != EOF) + while ((a = getopt(argc, argv, "hi:p:t:cs")) != EOF) #else - while ((a = getopt(argc, argv, "hp:t:c")) != EOF) + while ((a = getopt(argc, argv, "hi:p:t:c")) != EOF) #endif switch (a) { + case 'i': + strcpy(ip_addr, optarg); + break; case 'p': port = atoi(optarg); break; @@ -284,7 +298,8 @@ int main(int argc, char **argv) is_https = 1; break; default: - fprintf(stderr, "usage: webserver [-p http_port] " + fprintf(stderr, "usage: webserver " + "[-i ip_addr] [-p http_port] " "[-t tracefile] [-c] " #ifdef HAVE_OPENSSL "[-s] " @@ -334,7 +349,7 @@ int main(int argc, char **argv) * exits if it doesn't succeed. */ lprintf(2, "Attempting to bind to port %d...\n", port); - msock = ig_tcp_server(port, LISTEN_QUEUE_LENGTH); + msock = ig_tcp_server(ip_addr, port, LISTEN_QUEUE_LENGTH); lprintf(2, "Listening on socket %d\n", msock); signal(SIGPIPE, SIG_IGN);