* Added the ability to listen on a single IP address instead of all addresses.
authorArt Cancro <ajc@citadel.org>
Thu, 24 Jun 2004 14:50:35 +0000 (14:50 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 24 Jun 2004 14:50:35 +0000 (14:50 +0000)
webcit/ChangeLog
webcit/README.txt
webcit/webserver.c

index 9a8d4fc27f6fcc3e6720b56864f99f7ff3ef4788..efb81c33974175e7acf9162d49ac7fa8b46394f8 100644 (file)
@@ -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 <ajc@uncnsrd.mt-kisco.ny.us>
 
 1998-12-03 Nathan Bryant <bryant@cs.usm.maine.edu>
        * webserver.c: warning fix
+
index 4cf5ed2ee6c2c990f95a0f5adc301933f9dc8f22..6151b71753968efaa8ca261d999b5c5a91516594 100644 (file)
@@ -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
index 63d903024025c8bceeae8864461c0335a5a5f9ce..e6c7e45f35505f88f0a8286bc7a1b1fae58a6dee 100644 (file)
@@ -28,6 +28,7 @@
 #include <limits.h>
 #endif
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <string.h>
 #include <pwd.h>
@@ -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);