Subject: bin/2088: [dM] inetd can't specify host address
To: None <gnats-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 02/16/1996 15:10:37
>Number:         2088
>Category:       bin
>Synopsis:       [dM] inetd can't specify host address
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 16 16:35:02 1996
>Last-Modified:
>Originator:     der Mouse
>Organization:
Dis-
>Release:        -current supped Feb 16 early AM
>Environment:
	Any (I use /sparc and /sun3)
>Description:
	inetd, while very useful, does not support running different
	sets of services on different addresses.  In my application, a
	machine has a "secure" interface and an "insecure" interface.
	I want to run a couple of services (eg, identd) on all
	interfaces and a few more on just the "secure" interface.
	Rather than giving up on inetd, I added a command-line option
	specifying what host portion to use when binding sockets.  (I
	could have changed the inetd.conf format, which would perhaps
	have been preferable but would have been a good deal more work
	and also would have difficult to make backward-compatible.)
>How-To-Repeat:
	N/A
>Fix:
	I thought you'd never ask. :-)

--- OLD/usr.sbin/inetd/inetd.8	Thu Jan  1 00:00:00 1970
+++ NEW/usr.sbin/inetd/inetd.8	Thu Jan  1 00:00:00 1970
@@ -41,6 +41,7 @@
 .Dq super-server
 .Sh SYNOPSIS
 .Nm inetd
+.Op Fl a Ar address
 .Op Fl d
 .Op Ar configuration file
 .Sh DESCRIPTION
@@ -60,11 +61,24 @@
 allows running one daemon to invoke several others,
 reducing load on the system.
 .Pp
-The option available for
+The options available for
 .Nm inetd:
 .Bl -tag -width Ds
 .It Fl d
 Turns on debugging.
+.It Fl a
+Specifies the host part of the address
+.Nm
+will listen for connections on.  The argument can be a dotted-quad
+address or a host name acceptable to
+.Xr gethostbyname 3 .
+This is useful when (for any reason) you wish to run different services
+on different addresses.  By default,
+.Nm
+uses
+.Dv INADDR_ANY ,
+which causes it to accept incoming connections to any of the hosts'
+addresses.
 .El
 .Pp
 Upon execution,
--- OLD/usr.sbin/inetd/inetd.c	Thu Jan  1 00:00:00 1970
+++ NEW/usr.sbin/inetd/inetd.c	Thu Jan  1 00:00:00 1970
@@ -162,6 +162,7 @@
 int	timingout;
 struct	servent *sp;
 char	*curdom;
+struct in_addr locaddr;
 
 #ifndef OPEN_MAX
 #define OPEN_MAX	64
@@ -287,15 +288,29 @@
 	progname = strrchr(argv[0], '/');
 	progname = progname ? progname + 1 : argv[0];
 
-	while ((ch = getopt(argc, argv, "d")) != EOF)
+	locaddr.s_addr = INADDR_ANY;
+
+	while ((ch = getopt(argc, argv, "a:d")) != EOF)
 		switch(ch) {
+		case 'a':
+			if (! inet_aton(optarg,&locaddr)) {
+				struct hostent *hp;
+				hp = gethostbyname(optarg);
+				if (hp && (hp->h_addrtype == AF_INET) && (hp->h_length == sizeof(struct in_addr))) {
+					bcopy(hp->h_addr_list[0],&locaddr,sizeof(struct in_addr));
+				} else {
+					fprintf(stderr, "%s: invalid address argument `%s'\n", progname, optarg);
+					exit(1);
+				}
+			}
+			break;
 		case 'd':
 			debug = 1;
 			options |= SO_DEBUG;
 			break;
 		case '?':
 		default:
-			fprintf(stderr, "usage: %s [-d] [conf]", progname);
+			fprintf(stderr, "usage: %s [-a addr] [-d] [conf]\n", progname);
 			exit(1);
 		}
 	argc -= optind;
@@ -603,6 +618,7 @@
 			break;
 		case AF_INET:
 			sep->se_ctrladdr_in.sin_family = AF_INET;
+			sep->se_ctrladdr_in.sin_addr = locaddr;
 			sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in;
 			if (isrpcservice(sep)) {
 				struct rpcent *rp;

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: