]> arthur.barton.de Git - ngircd-alex.git/commitdiff
New configuration option "Listen" to bind the server to a specific ip.
authorAlexander Barton <alex@barton.de>
Thu, 11 Sep 2003 12:05:28 +0000 (12:05 +0000)
committerAlexander Barton <alex@barton.de>
Thu, 11 Sep 2003 12:05:28 +0000 (12:05 +0000)
ChangeLog
NEWS
doc/sample-ngircd.conf
man/ngircd.conf.5
src/ngircd/conf.c
src/ngircd/conf.h
src/ngircd/conn.c

index 111dad2734eb4ef0e7fd994eb00167b0dfdc8299..fc3767a20c8f263d0eada797d3a6ed0a7932172e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@
 
 ngIRCd CVS-HEAD
 
 
 ngIRCd CVS-HEAD
 
+  - Added new configuration variable "Listen" to bind all listening
+    sockets of the server to a single IP address.
   - Suppress misleading error message of diff during make run.
   - Enhanced test-suite and made it work on GNU/Hurd.
   - Fixed minor typo in debug output :-)
   - Suppress misleading error message of diff during make run.
   - Enhanced test-suite and made it work on GNU/Hurd.
   - Fixed minor typo in debug output :-)
@@ -464,4 +466,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
 
 
 -- 
-$Id: ChangeLog,v 1.210 2003/09/09 13:24:41 alex Exp $
+$Id: ChangeLog,v 1.211 2003/09/11 12:05:28 alex Exp $
diff --git a/NEWS b/NEWS
index 4ace41026168d1f162e93243958c2492b20e4b80..c55b2b4eb6f52c94bbcfa8ec2f37ecdd028faae5 100644 (file)
--- a/NEWS
+++ b/NEWS
                                   -- NEWS --
 
 
                                   -- NEWS --
 
 
+ngIRCd CVS-HEAD
+
+  - Added new configuration variable "Listen" to bind all listening
+    sockets of the server to a single IP address.
+       
 ngIRCd 0.7.1 (2003-07-18)
 
   - Added support for GNU/Hurd.
 ngIRCd 0.7.1 (2003-07-18)
 
   - Added support for GNU/Hurd.
@@ -165,4 +170,4 @@ ngIRCd 0.0.1, 31.12.2001
 
 
 -- 
 
 
 -- 
-$Id: NEWS,v 1.57 2003/08/30 20:37:15 alex Exp $
+$Id: NEWS,v 1.58 2003/09/11 12:05:28 alex Exp $
index ca5c29926403a21db0ccad7c487d958542f19a51..354b54efa7b3fa8cf2789fe9af911023138f1062 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: sample-ngircd.conf,v 1.22 2003/04/29 12:36:09 alex Exp $
+# $Id: sample-ngircd.conf,v 1.23 2003/09/11 12:05:28 alex Exp $
 
 #
 # This is a sample configuration file for the ngIRCd, which must adept to
 
 #
 # This is a sample configuration file for the ngIRCd, which must adept to
        # Ports on which the server should listen. There may be more than
        # one port, separated with ";". (Default: 6667)
        ;Ports = 6667, 6668, 66694
        # Ports on which the server should listen. There may be more than
        # one port, separated with ";". (Default: 6667)
        ;Ports = 6667, 6668, 66694
+
+       # IP address on which the server should listen. (Default: empty,
+       # so the server listens on all IP addresses of the system)
+       ;Listen = 1.2.3.4
        
        # Text file with the "message of the day" (MOTD). This message will
        # be shown to all users connecting to the server:
        
        # Text file with the "message of the day" (MOTD). This message will
        # be shown to all users connecting to the server:
index 56a0e594511a8c5ebb287b175536caa6179c0189..773287a7ee09fb43c0e995a1dfab77f38b448389 100644 (file)
@@ -1,5 +1,5 @@
 .\"
 .\"
-.\" $Id: ngircd.conf.5,v 1.10 2003/05/02 20:51:42 alex Exp $
+.\" $Id: ngircd.conf.5,v 1.11 2003/09/11 12:05:28 alex Exp $
 .\"
 .TH ngircd.conf 5 "Mai 2003" ngircd "ngIRCd Manual"
 .SH NAME
 .\"
 .TH ngircd.conf 5 "Mai 2003" ngircd "ngIRCd Manual"
 .SH NAME
@@ -67,6 +67,10 @@ command.
 Ports on which the server should listen. There may be more than one port,
 separated with ';'. Default: 6667.
 .TP
 Ports on which the server should listen. There may be more than one port,
 separated with ';'. Default: 6667.
 .TP
+\fBListen\fR
+The ip address on which the server should listen. Default is empty, so
+the server listens on all configured ip addresses and interfaces.
+.TP
 \fBMotdFile\fR
 Text file with the "message of the day" (MOTD). This message will be shown
 to all users connecting to the server.
 \fBMotdFile\fR
 Text file with the "message of the day" (MOTD). This message will be shown
 to all users connecting to the server.
index 00b5bb795274a4dc3fa280c5cca4c936fbbb8e89..0abb3c81531c40d791cef63ddc41113f3b1d2b1f 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conf.c,v 1.59 2003/04/29 12:36:09 alex Exp $";
+static char UNUSED id[] = "$Id: conf.c,v 1.60 2003/09/11 12:05:28 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
 
 #include "imp.h"
 #include <assert.h>
@@ -120,6 +120,7 @@ Conf_Test( VOID )
                printf( "%u", Conf_ListenPorts[i] );
        }
        puts( "" );
                printf( "%u", Conf_ListenPorts[i] );
        }
        puts( "" );
+       printf( "  Listen = %s\n", Conf_ListenAddress );
        pwd = getpwuid( Conf_UID );
        if( pwd ) printf( "  ServerUID = %s\n", pwd->pw_name );
        else printf( "  ServerUID = %ld\n", (LONG)Conf_UID );
        pwd = getpwuid( Conf_UID );
        if( pwd ) printf( "  ServerUID = %s\n", pwd->pw_name );
        else printf( "  ServerUID = %ld\n", (LONG)Conf_UID );
@@ -340,6 +341,7 @@ Set_Defaults( BOOLEAN InitServers )
        strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
 
        Conf_ListenPorts_Count = 0;
        strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
 
        Conf_ListenPorts_Count = 0;
+       strcpy( Conf_ListenAddress, "" );
 
        Conf_UID = Conf_GID = 0;
        
 
        Conf_UID = Conf_GID = 0;
        
@@ -699,6 +701,15 @@ Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
                Conf_MaxJoins = atoi( Arg );
                return;
        }
                Conf_MaxJoins = atoi( Arg );
                return;
        }
+       if( strcasecmp( Var, "Listen" ) == 0 )
+       {
+               /* IP-Address to bind sockets */
+               if( strlcpy( Conf_ListenAddress, Arg, sizeof( Conf_ListenAddress )) >= sizeof( Conf_ListenAddress ))
+               {
+                       Config_Error( LOG_WARNING, "%s, line %d: Value of \"Listen\" too long!", NGIRCd_ConfFile, Line );
+                       return;
+               }
+       }
 
        Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
 } /* Handle_GLOBAL */
 
        Config_Error( LOG_ERR, "%s, line %d (section \"Global\"): Unknown variable \"%s\"!", NGIRCd_ConfFile, Line, Var );
 } /* Handle_GLOBAL */
index 47784ba40d94c942a8634cc26cdb8c16c9679617..15a7093d433bb08b7033ab2135fdbf691fd47c5c 100644 (file)
@@ -8,7 +8,7 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: conf.h,v 1.26 2002/12/31 16:12:50 alex Exp $
+ * $Id: conf.h,v 1.27 2003/09/11 12:05:28 alex Exp $
  *
  * Configuration management (header)
  */
  *
  * Configuration management (header)
  */
@@ -76,6 +76,9 @@ GLOBAL CHAR Conf_MotdFile[FNAME_LEN];
 GLOBAL UINT Conf_ListenPorts[MAX_LISTEN_PORTS];
 GLOBAL INT Conf_ListenPorts_Count;
 
 GLOBAL UINT Conf_ListenPorts[MAX_LISTEN_PORTS];
 GLOBAL INT Conf_ListenPorts_Count;
 
+/* Address to which the socket should be bound or empty (=all) */
+GLOBAL CHAR Conf_ListenAddress[16];
+
 /* User and group ID the server should run with */
 GLOBAL UINT Conf_UID;
 GLOBAL UINT Conf_GID;
 /* User and group ID the server should run with */
 GLOBAL UINT Conf_UID;
 GLOBAL UINT Conf_GID;
index 1c16b5da7250cbe094b0c02d818138368b9ca502..56824594e98fc22629b26f8296663b796ba78fb0 100644 (file)
@@ -16,7 +16,7 @@
 
 #include "portab.h"
 
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: conn.c,v 1.124 2003/08/30 20:28:54 alex Exp $";
+static char UNUSED id[] = "$Id: conn.c,v 1.125 2003/09/11 12:05:28 alex Exp $";
 
 #include "imp.h"
 #include <assert.h>
 
 #include "imp.h"
 #include <assert.h>
@@ -236,6 +236,7 @@ Conn_NewListener( CONST UINT Port )
        /* Create new listening socket on specified port */
 
        struct sockaddr_in addr;
        /* Create new listening socket on specified port */
 
        struct sockaddr_in addr;
+       struct in_addr inaddr;
        INT sock;
 #ifdef RENDEZVOUS
        CHAR name[CLIENT_ID_LEN], *info;
        INT sock;
 #ifdef RENDEZVOUS
        CHAR name[CLIENT_ID_LEN], *info;
@@ -243,9 +244,24 @@ Conn_NewListener( CONST UINT Port )
 
        /* Server-"Listen"-Socket initialisieren */
        memset( &addr, 0, sizeof( addr ));
 
        /* Server-"Listen"-Socket initialisieren */
        memset( &addr, 0, sizeof( addr ));
+       memset( &inaddr, 0, sizeof( inaddr ));
        addr.sin_family = AF_INET;
        addr.sin_port = htons( Port );
        addr.sin_family = AF_INET;
        addr.sin_port = htons( Port );
-       addr.sin_addr.s_addr = htonl( INADDR_ANY );
+       if( Conf_ListenAddress[0] )
+       {
+#ifdef HAVE_INET_ATON
+               if( inet_aton( Conf_ListenAddress, &inaddr ) == 0 )
+#else
+               inaddr.s_addr = inet_addr( Conf_ListenAddress );
+               if( inaddr.s_addr == (unsigned)-1 )
+#endif
+               {
+                       Log( LOG_CRIT, "Can't listen on %s:%u: can't convert ip address %s!", Conf_ListenAddress, Port, Conf_ListenAddress );
+                       return FALSE;
+               }
+       }
+       else inaddr.s_addr = htonl( INADDR_ANY );
+       addr.sin_addr = inaddr;
 
        /* Socket erzeugen */
        sock = socket( PF_INET, SOCK_STREAM, 0);
 
        /* Socket erzeugen */
        sock = socket( PF_INET, SOCK_STREAM, 0);
@@ -279,7 +295,8 @@ Conn_NewListener( CONST UINT Port )
 
        if( sock > Conn_MaxFD ) Conn_MaxFD = sock;
 
 
        if( sock > Conn_MaxFD ) Conn_MaxFD = sock;
 
-       Log( LOG_INFO, "Now listening on port %d (socket %d).", Port, sock );
+       if( Conf_ListenAddress[0]) Log( LOG_INFO, "Now listening on %s:%d (socket %d).", Conf_ListenAddress, Port, sock );
+       else Log( LOG_INFO, "Now listening on 0.0.0.0:%d (socket %d).", Port, sock );
 
 #ifdef RENDEZVOUS
        /* Get best server description text */
 
 #ifdef RENDEZVOUS
        /* Get best server description text */