From ded15325373a553ab1407b42ec9b103fcb0fbd84 Mon Sep 17 00:00:00 2001
From: Benedetto <dettox@gmail.com>
Date: Thu, 8 Oct 2015 16:37:39 +0000
Subject: [PATCH] 	modified:   src/btsched.c
 	modified:   src/hdrs/sh_ext.h
 	modified:   src/sh_network.c

---
 src/btsched.c     |   21 +++++++++++++++++----
 src/hdrs/sh_ext.h |    2 +-
 src/sh_network.c  |   17 +++++++++++++----
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/src/btsched.c b/src/btsched.c
index 309c315..b8759d3 100644
--- a/src/btsched.c
+++ b/src/btsched.c
@@ -1167,6 +1167,8 @@ MAINFN_TYPE  main(int argc, char **argv)
 {
         LONG    initll = -1L;   /* Set to indicate leave alone */
         LONG    jsize = 0L, vsize = 0L;
+	int	laddr = 0;
+	char 	*addr;
         int     chku;
 #ifndef DEBUG
         PIDTYPE pid;
@@ -1194,7 +1196,8 @@ MAINFN_TYPE  main(int argc, char **argv)
                 -v nnn initial number of vars
                 -d nnnn.nnn set pri_decrement
                 -t turn off use of setpgrp
-                -n no network */
+                -n no network 
+                -a nnn.nnn.nnn.nnn listen on address */
 
         argv++;
         while  (*argv  &&  argv[0][0] == '-')  {
@@ -1212,6 +1215,9 @@ MAINFN_TYPE  main(int argc, char **argv)
                         nosetpgrp++;
                         argv++;
                         continue;
+                case  'a':
+                        laddr = 1;
+			break;
                 case  'l':
                         wh = &initll;
                         break;
@@ -1242,8 +1248,15 @@ MAINFN_TYPE  main(int argc, char **argv)
                 else  {
                         argv++;
                         if  (argv[0])  {
-                                *wh = atol(argv[0]);
-                                argv++;
+				if (laddr) {
+					addr = malloc(strlen(argv[0])*sizeof(char)+1);
+					strcpy(addr,argv[0]);
+					laddr = 0;
+                       			argv++;
+				} else {
+                                	*wh = atol(argv[0]);
+                                	argv++;
+				}
                         }
                 }
         }
@@ -1424,7 +1437,7 @@ MAINFN_TYPE  main(int argc, char **argv)
                    Start up net monitor process */
 
                 init_remotelock();
-                attach_hosts();
+                attach_hosts(addr);
                 net_initvsync();
                 net_initjsync();        /* Also splats ci file across */
                 netmonitor();
diff --git a/src/hdrs/sh_ext.h b/src/hdrs/sh_ext.h
index 63ff00b..6161fca 100644
--- a/src/hdrs/sh_ext.h
+++ b/src/hdrs/sh_ext.h
@@ -128,7 +128,7 @@ extern PIDTYPE  forksafe();
 extern vhash_t  findvar(const vident *);
 extern vhash_t  lookvar(Vref *);
 extern BtvarRef  locvarind(ShreqRef, const vhash_t);
-extern void  attach_hosts();
+extern void  attach_hosts(char *);
 extern void  ci_broadcast();
 extern void  ci_delhost(const unsigned);
 extern void  ci_remaphost(const unsigned, const unsigned, CCmdintRef);
diff --git a/src/sh_network.c b/src/sh_network.c
index 329dc07..4472c93 100644
--- a/src/sh_network.c
+++ b/src/sh_network.c
@@ -742,7 +742,7 @@ static  int     get_serv_port(char **slist, const int proto, unsigned sn)
 
 /* Attach hosts if possible */
 
-void  attach_hosts()
+void  attach_hosts(char *addr)
 {
         struct  remote  *rp;
         char    *ep;
@@ -789,7 +789,10 @@ void  attach_hosts()
                 sin.sin_family = AF_INET;
                 sin.sin_port = lportnum;
                 BLOCK_ZERO(sin.sin_zero, sizeof(sin.sin_zero));
-                sin.sin_addr.s_addr = INADDR_ANY;
+                if(addr)
+			sin.sin_addr.s_addr = inet_addr(addr);
+                else
+                	sin.sin_addr.s_addr = INADDR_ANY;
                 if  (bind(listsock, (struct sockaddr *) &sin, sizeof(sin)) < 0  ||  listen(listsock, 5) < 0)  {
                         close(listsock);
                         listsock = -1;
@@ -809,7 +812,10 @@ void  attach_hosts()
                 sin.sin_family = AF_INET;
                 sin.sin_port = vportnum;
                 BLOCK_ZERO(sin.sin_zero, sizeof(sin.sin_zero));
-                sin.sin_addr.s_addr = INADDR_ANY;
+                if(addr)
+			sin.sin_addr.s_addr = inet_addr(addr);
+                else
+                	sin.sin_addr.s_addr = INADDR_ANY;
                 if  (bind(viewsock, (struct sockaddr *) &sin, sizeof(sin)) < 0  ||  listen(viewsock, 5) < 0)  {
                         close(viewsock);
                         viewsock = -1;
@@ -826,7 +832,10 @@ void  attach_hosts()
                 sin.sin_family = AF_INET;
                 sin.sin_port = pportnum;
                 BLOCK_ZERO(sin.sin_zero, sizeof(sin.sin_zero));
-                sin.sin_addr.s_addr = INADDR_ANY;
+                if(addr)
+			sin.sin_addr.s_addr = inet_addr(addr);
+                else
+                	sin.sin_addr.s_addr = INADDR_ANY;
                 if  (bind(probesock, (struct sockaddr *) &sin, sizeof(sin)) < 0)  {
                         close(probesock);
                         probesock = -1;
-- 
1.7.2.3

