[PATCH] change localip is6 flag based on destination ip

From: John Regan <john_at_jrjrtech.com>
Date: Wed, 11 Apr 2018 14:48:30 -0400

By default, the localip flag is initialized with
the is6 flag set to 0. The only time the flag is
changed to 1 is when a user specifies a local IPv6
address to use.

Because of this, socket_tcp46 always creates an IPv4
socket.

This patch corrects that - if the user hasn't specified
a local address, then the local 'is6' flag is updated
to match the destination 'is6' flag.
---
 src/conn-tools/s6-tcpclient.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/conn-tools/s6-tcpclient.c b/src/conn-tools/s6-tcpclient.c
index 062047c..5fdd7f0 100644
--- a/src/conn-tools/s6-tcpclient.c
+++ b/src/conn-tools/s6-tcpclient.c
_at_@ -56,6 +56,7 @@ static tain_t deadline ;
 int main (int argc, char const *const *argv)
 {
   int s ;
+  int localip = 0;
   tflags flags = TFLAGS_DEFAULT ;
   uint16_t remoteport ;
   PROG = "s6-tcpclient" ;
_at_@ -97,7 +98,7 @@ int main (int argc, char const *const *argv)
           if (!uint0_scan(l.arg + n + 1, &flags.timeoutconn[1])) usage() ;
           break ;
         }
-        case 'i' : if (!ip46_scan(l.arg, &flags.localip)) usage() ; break ;
+        case 'i' : if (!ip46_scan(l.arg, &flags.localip)) usage() ; localip = 1 ; break ;
         case 'p' : if (!uint160_scan(l.arg, &flags.localport)) usage() ; break ;
         default : usage() ;
       }
_at_@ -222,7 +223,10 @@ int main (int argc, char const *const *argv)
       for (; i < n[j] ; i++)
       {
         tain_t localdeadline ;
-        s = socket_tcp46(ip46_is6(&flags.localip)) ;
+#ifdef SKALIBS_IPV6_ENABLED
+        if(!localip) flags.localip.is6 = ip46_is6(&ip[j][i]);
+#endif
+        s = socket_tcp46(ip46_is6(&flags.localip));
         if (s < 0) strerr_diefu1sys(111, "create socket") ;
         if (socket_bind46(s, &flags.localip, flags.localport) < 0)
           strerr_diefu1sys(111, "bind socket") ;
-- 
2.7.4
Received on Wed Apr 11 2018 - 18:48:30 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC