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
>Originator:     der Mouse
>Release:        -current supped Feb 16 early AM
	Any (I use /sparc and /sun3)
	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.)
	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
 .Nm inetd
+.Op Fl a Ar address
 .Op Fl d
 .Op Ar configuration file
@@ -60,11 +61,24 @@
 allows running one daemon to invoke several others,
 reducing load on the system.
-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
+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,
+which causes it to accept incoming connections to any of the hosts'
 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;
 		case '?':
-			fprintf(stderr, "usage: %s [-d] [conf]", progname);
+			fprintf(stderr, "usage: %s [-a addr] [-d] [conf]\n", progname);
 	argc -= optind;
@@ -603,6 +618,7 @@
 		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