Index: inetd.c
===================================================================
RCS file: /prod/cvsroot/usr.src/usr.sbin/inetd/inetd.c,v
retrieving revision 1.1.1.2
diff -c -b -r1.1.1.2 inetd.c
*** inetd.c	1995/06/27 00:13:09	1.1.1.2
--- inetd.c	1995/06/29 08:11:06
***************
*** 40,46 ****
  
  #ifndef lint
  /*static char sccsid[] = "from: @(#)inetd.c	5.30 (Berkeley) 6/3/91";*/
! static char rcsid[] = "$Id: inetd.c,v 1.1.1.2 1995/06/27 00:13:09 sjg Exp $";
  #endif /* not lint */
  
  /*
--- 40,46 ----
  
  #ifndef lint
  /*static char sccsid[] = "from: @(#)inetd.c	5.30 (Berkeley) 6/3/91";*/
! static char rcsid[] = "$Id: inetd.c,v 1.3 1995/06/27 05:12:59 sjg Exp $";
  #endif /* not lint */
  
  /*
***************
*** 251,256 ****
--- 251,259 ----
  char 	*LastArg;
  char	*progname;
  
+ unsigned long *Addrs = NULL;
+ int Naddrs = 0;
+ 
  #ifdef sun
  /*
   * Sun's RPC library caches the result of `dtablesize()'
***************
*** 263,268 ****
--- 266,299 ----
  }
  #endif
  
+ void
+ build_alist(list)
+ 	char *list;
+ {
+ 	char *tmp = strdup(list);
+ 	char *cp, *cp2;
+ 	int i;
+ 
+ 	for (Naddrs = 0, cp = tmp; cp && *cp; cp = cp2) {
+ 		Naddrs++;
+ 		if (cp2 =  strchr(cp, ','))
+ 			cp2++;
+ 	}
+ 	Addrs = (unsigned long *) malloc(sizeof(unsigned long *) * Naddrs + 1);
+ 	if (Addrs) {
+ 		for (cp = tmp, i = 0; cp; cp = cp2) {
+ 			if (cp2 = strchr(cp, ','))
+ 				*cp2++ = '\0';
+ 			if (*cp) {
+ 				Addrs[i++] = inet_addr(cp);
+ 			}
+ 		}
+ 		Addrs[i++] = 0;
+ 	}
+ 	free(tmp);
+ }
+ 
+ 
  main(argc, argv, envp)
  	int argc;
  	char *argv[], *envp[];
***************
*** 287,294 ****
  	progname = strrchr(argv[0], '/');
  	progname = progname ? progname + 1 : argv[0];
  
! 	while ((ch = getopt(argc, argv, "d")) != EOF)
  		switch(ch) {
  		case 'd':
  			debug = 1;
  			options |= SO_DEBUG;
--- 318,328 ----
  	progname = strrchr(argv[0], '/');
  	progname = progname ? progname + 1 : argv[0];
  
! 	while ((ch = getopt(argc, argv, "a:d")) != EOF)
  		switch(ch) {
+ 		case 'a':
+ 			build_alist(optarg);
+ 			break;
  		case 'd':
  			debug = 1;
  			options |= SO_DEBUG;
***************
*** 534,539 ****
--- 568,575 ----
  	struct servtab *getconfigent(), *enter();
  	long omask;
  	int n;
+ 	int i;
+ 	int old;
  
  	if (!setconfig()) {
  		syslog(LOG_ERR, "%s: %m", CONFIG);
***************
*** 546,557 ****
  			if (strcmp(sep->se_service, cp->se_service) == 0 &&
  			    strcmp(sep->se_proto, cp->se_proto) == 0)
  				break;
! 		if (sep != 0) {
! 			int i;
  
  #define SWAP(type, a, b) {type c=(type)a; (type)a=(type)b; (type)b=(type)c;}
  
  			omask = sigblock(SIGBLOCK);
  			/*
  			 * sep->se_wait may be holding the pid of a daemon
  			 * that we're waiting for.  If so, don't overwrite
--- 582,598 ----
  			if (strcmp(sep->se_service, cp->se_service) == 0 &&
  			    strcmp(sep->se_proto, cp->se_proto) == 0)
  				break;
! 
! 		old = (sep != 0);
! 		n = 0;
! 		
! 		do {
! 			if (old) {
  
  #define SWAP(type, a, b) {type c=(type)a; (type)a=(type)b; (type)b=(type)c;}
  
  			omask = sigblock(SIGBLOCK);
+ 			
  			/*
  			 * sep->se_wait may be holding the pid of a daemon
  			 * that we're waiting for.  If so, don't overwrite
***************
*** 577,587 ****
  			sep->se_rpcversl = cp->se_rpcversl;
  			sep->se_rpcversh = cp->se_rpcversh;
  			sigsetmask(omask);
- 			freeconfig(cp);
  			if (debug)
  				print_service("REDO", sep);
  		} else {
  			sep = enter(cp);
  			if (debug)
  				print_service("ADD ", sep);
  		}
--- 618,628 ----
  			sep->se_rpcversl = cp->se_rpcversl;
  			sep->se_rpcversh = cp->se_rpcversh;
  			sigsetmask(omask);
  			if (debug)
  				print_service("REDO", sep);
  		} else {
  			sep = enter(cp);
+ 			
  			if (debug)
  				print_service("ADD ", sep);
  		}
***************
*** 592,608 ****
  			if (sep->se_fd != -1)
  				break;
  			(void)unlink(sep->se_service);
! 			n = strlen(sep->se_service);
! 			if (n > sizeof sep->se_ctrladdr_un.sun_path - 1) 
! 				n = sizeof sep->se_ctrladdr_un.sun_path - 1;
! 			strncpy(sep->se_ctrladdr_un.sun_path, sep->se_service, n);
  			sep->se_ctrladdr_un.sun_family = AF_UNIX;
! 			sep->se_ctrladdr_size = n +
  					sizeof sep->se_ctrladdr_un.sun_family;
  			setup(sep);
  			break;
  		case AF_INET:
  			sep->se_ctrladdr_in.sin_family = AF_INET;
  			sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in;
  			if (isrpcservice(sep)) {
  				struct rpcent *rp;
--- 633,653 ----
  			if (sep->se_fd != -1)
  				break;
  			(void)unlink(sep->se_service);
! 				i = strlen(sep->se_service);
! 				if (i > sizeof sep->se_ctrladdr_un.sun_path - 1) 
! 					i = sizeof sep->se_ctrladdr_un.sun_path - 1;
! 				strncpy(sep->se_ctrladdr_un.sun_path, sep->se_service, i);
  			sep->se_ctrladdr_un.sun_family = AF_UNIX;
! 				sep->se_ctrladdr_size = i +
  					sizeof sep->se_ctrladdr_un.sun_family;
  			setup(sep);
  			break;
  		case AF_INET:
  			sep->se_ctrladdr_in.sin_family = AF_INET;
+ 				if (Naddrs)
+ 					sep->se_ctrladdr_in.sin_addr.s_addr = Addrs[n];
+ 				else
+ 					sep->se_ctrladdr_in.sin_addr.s_addr = INADDR_ANY;
  			sep->se_ctrladdr_size = sizeof sep->se_ctrladdr_in;
  			if (isrpcservice(sep)) {
  				struct rpcent *rp;
***************
*** 649,654 ****
--- 694,707 ----
  					setup(sep);
  			}
  		}
+ 			if (++n < Naddrs && cp->se_family != AF_UNIX) {
+ 				if (old)
+ 					sep = sep->se_next;
+ 			} else
+ 				break;
+ 		} while (sep) ;
+ 		if (old)
+ 			freeconfig(cp);
  	}
  	endconfig();
  	/*
Index: inetd.8
===================================================================
RCS file: /prod/cvsroot/usr.src/usr.sbin/inetd/inetd.8,v
retrieving revision 1.1.1.1
diff -c -b -r1.1.1.1 inetd.8
*** inetd.8	1995/04/11 08:32:19	1.1.1.1
--- inetd.8	1995/04/12 00:29:15
***************
*** 30,36 ****
  .\" SUCH DAMAGE.
  .\"
  .\"     from: @(#)inetd.8	6.7 (Berkeley) 3/16/91
! .\"	$Id: inetd.8,v 1.1.1.1 1995/04/11 08:32:19 sjg Exp $
  .\"
  .Dd March 16, 1991
  .Dt INETD 8
--- 30,36 ----
  .\" SUCH DAMAGE.
  .\"
  .\"     from: @(#)inetd.8	6.7 (Berkeley) 3/16/91
! .\"	$Id: inetd.8,v 1.2 1995/04/12 00:29:15 sjg Exp $
  .\"
  .Dd March 16, 1991
  .Dt INETD 8
***************
*** 42,47 ****
--- 42,48 ----
  .Sh SYNOPSIS
  .Nm inetd
  .Op Fl d
+ .Op Fl a Ar addr_list
  .Op Ar configuration file
  .Sh DESCRIPTION
  .Nm Inetd
***************
*** 65,70 ****
--- 66,82 ----
  .Bl -tag -width Ds
  .It Fl d
  Turns on debugging.
+ .It Fl a Ar addr_list
+ This option tells
+ .Nm inetd
+ to only provide the services in the
+ .Ar configuration file
+ on the addresses in
+ .Ar addr_list
+ (a coma separated list).
+ This allows a multi-homed host to run multiple  
+ .Nm inetd
+ processes and offer different services to each network interface.
  .El
  .Pp
  Upon execution,
