about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2003-09-11 12:05:28 +0000
committerAlexander Barton <alex@barton.de>2003-09-11 12:05:28 +0000
commite33ab90379240cc99f0790d5d68a688ea32d4d9a (patch)
tree419cd7f63e0b1311128c350c4c8ec6d1dc81e4fa /src
parentd8f3c2b42bfa70ff77ced9483e3efd51c1271d83 (diff)
downloadngircd-e33ab90379240cc99f0790d5d68a688ea32d4d9a.tar.gz
ngircd-e33ab90379240cc99f0790d5d68a688ea32d4d9a.zip
New configuration option "Listen" to bind the server to a specific ip.
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conf.c13
-rw-r--r--src/ngircd/conf.h5
-rw-r--r--src/ngircd/conn.c23
3 files changed, 36 insertions, 5 deletions
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index 00b5bb79..0abb3c81 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -14,7 +14,7 @@
 
 #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>
@@ -120,6 +120,7 @@ Conf_Test( VOID )
 		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 );
@@ -340,6 +341,7 @@ Set_Defaults( BOOLEAN InitServers )
 	strlcat( Conf_MotdFile, MOTD_FILE, sizeof( Conf_MotdFile ));
 
 	Conf_ListenPorts_Count = 0;
+	strcpy( Conf_ListenAddress, "" );
 
 	Conf_UID = Conf_GID = 0;
 	
@@ -699,6 +701,15 @@ Handle_GLOBAL( INT Line, CHAR *Var, CHAR *Arg )
 		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 */
diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h
index 47784ba4..15a7093d 100644
--- a/src/ngircd/conf.h
+++ b/src/ngircd/conf.h
@@ -8,7 +8,7 @@
  * (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)
  */
@@ -76,6 +76,9 @@ GLOBAL CHAR Conf_MotdFile[FNAME_LEN];
 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;
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 1c16b5da..56824594 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -16,7 +16,7 @@
 
 #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>
@@ -236,6 +236,7 @@ Conn_NewListener( CONST UINT Port )
 	/* 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;
@@ -243,9 +244,24 @@ Conn_NewListener( CONST UINT Port )
 
 	/* 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_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);
@@ -279,7 +295,8 @@ Conn_NewListener( CONST UINT Port )
 
 	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 */