summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/s6-tcpclient.html10
-rw-r--r--src/conn-tools/s6-tcpclient.c31
-rw-r--r--src/conn-tools/s6-tcpserverd.c121
3 files changed, 86 insertions, 76 deletions
diff --git a/doc/s6-tcpclient.html b/doc/s6-tcpclient.html
index 0421524..39da083 100644
--- a/doc/s6-tcpclient.html
+++ b/doc/s6-tcpclient.html
@@ -80,15 +80,11 @@ the current connection (very unreliable). Else unset. </li>
<li> <tt>-q</tt>&nbsp;: be quiet. </li>
<li> <tt>-Q</tt>&nbsp;: be normally verbose. This is the default. </li>
<li> <tt>-v</tt>&nbsp;: be verbose. </li>
- <li> <tt>-4</tt>&nbsp;: (only valid if the underlying skalibs has
-IPv6 support) Interpret <em>host</em> as an IPv4 address or make A
-queries to determine its addresses. </li>
+ <li> <tt>-4</tt>&nbsp;: Interpret <em>host</em> as an IPv4 address or make A
+queries to determine its addresses. Do not attempt IPv6. </li>
<li> <tt>-6</tt>&nbsp;: (only valid if the underlying skalibs has
IPv6 support) Interpret <em>host</em> as an IPv6 address or make
-AAAA queries to determine its addresses. This option and the previous
-one are not mutually exclusive: if both are given, both IPv6 and
-IPv4 addresses will be tried and IPv6 addresses will be given priority.
-If neither option is given, only IPv4 address will be tried. </li>
+AAAA queries to determine its addresses. Do not attempt IPv4. </li>
<li> <tt>-d</tt>&nbsp;: don't use the TCP_NODELAY socket option. This
is the default. </li>
<li> <tt>-D</tt>&nbsp;: use the TCP_NODELAY socket option, which disables
diff --git a/src/conn-tools/s6-tcpclient.c b/src/conn-tools/s6-tcpclient.c
index 0224abd..1dea006 100644
--- a/src/conn-tools/s6-tcpclient.c
+++ b/src/conn-tools/s6-tcpclient.c
@@ -25,12 +25,12 @@
#ifdef SKALIBS_IPV6_ENABLED
# define USAGE "s6-tcpclient [ -q | -Q | -v ] [ -4 | -6 ] [ -d | -D ] [ -r | -R ] [ -h ] [ -H ] [ -n | -N ] [ -t timeoutinfo ] [ -l localname ] [ -T timeoutconn ] [ -i localip ] [ -p localport ] host port prog..."
-# define TFLAGS_DEFAULT { 0, 0, { 2, 58 }, IP46_ZERO, 0, 1, 0, 0, 1, 0, 1, 0, 1 }
# define OPTSTRING "qQv46dDrRhHnNt:l:T:i:p:"
+# define FLAGIP6_DEFAULT 1
#else
-# define USAGE "s6-tcpclient [ -q | -Q | -v ] [ -d | -D ] [ -r | -R ] [ -h ] [ -H ] [ -n | -N ] [ -t timeoutinfo ] [ -l localname ] [ -T timeoutconn ] [ -i localip ] [ -p localport ] host port prog..."
-# define TFLAGS_DEFAULT { 0, 0, { 2, 58 }, IP46_ZERO, 0, 1, 1, 0, 1, 0, 1 }
+# define USAGE "s6-tcpclient [ -q | -Q | -v ] [ -4 ] [ -d | -D ] [ -r | -R ] [ -h ] [ -H ] [ -n | -N ] [ -t timeoutinfo ] [ -l localname ] [ -T timeoutconn ] [ -i localip ] [ -p localport ] host port prog..."
# define OPTSTRING "qQvdDrRhHnNt:l:T:i:p:"
+# define FLAGIP6_DEFAULT 0
#endif
#define usage() strerr_dieusage(100, USAGE)
@@ -47,16 +47,30 @@ struct tflags_s
ip46 localip ;
uint16_t localport ;
unsigned int verbosity : 2 ;
-#ifdef SKALIBS_IPV6_ENABLED
unsigned int ip4 : 1 ;
unsigned int ip6 : 1 ;
-#endif
unsigned int delay : 1 ;
unsigned int remoteinfo : 1 ;
unsigned int remotehost : 1 ;
unsigned int hosts : 1 ;
unsigned int qualif : 1 ;
} ;
+#define TFLAGS_DEFAULT \
+{ \
+ .localname = 0,\
+ .timeout = 0,\
+ .timeoutconn = { 2, 58 }, \
+ .localip = IP46_ZERO, \
+ .localport = 0, \
+ .verbosity = 1, \
+ .ip4 = 1, \
+ .ip6 = FLAGIP6_DEFAULT, \
+ .delay = 1, \
+ .remoteinfo = 0, \
+ .remotehost = 1, \
+ .hosts = 0, \
+ .qualif = 1 \
+}
static tain deadline ;
@@ -78,9 +92,9 @@ int main (int argc, char const *const *argv)
case 'q' : if (flags.verbosity) flags.verbosity-- ; break ;
case 'Q' : flags.verbosity = 1 ; break ;
case 'v' : flags.verbosity++ ; break ;
+ case '4' : flags.ip4 = 1 ; flags.ip6 = 0 ; break ;
#ifdef SKALIBS_IPV6_ENABLED
- case '4' : flags.ip4 = 1 ; break ;
- case '6' : flags.ip6 = 1 ; break ;
+ case '6' : flags.ip6 = 1 ; flags.ip4 = 0 ; break ;
#endif
case 'd' : flags.delay = 1 ; break ;
case 'D' : flags.delay = 0 ; break ;
@@ -113,9 +127,6 @@ int main (int argc, char const *const *argv)
argc -= l.ind ; argv += l.ind ;
}
if (argc < 3) usage() ;
-#ifdef SKALIBS_IPV6_ENABLED
- if (!flags.ip6) flags.ip4 = 1 ;
-#endif
if (!uint160_scan(argv[1], &remoteport))
strerr_dief2x(100, "invalid port number: ", argv[1]) ;
tain_now_set_stopwatch_g() ;
diff --git a/src/conn-tools/s6-tcpserverd.c b/src/conn-tools/s6-tcpserverd.c
index 21946d9..46886c7 100644
--- a/src/conn-tools/s6-tcpserverd.c
+++ b/src/conn-tools/s6-tcpserverd.c
@@ -296,8 +296,13 @@ static inline void new_connection (int s, char const *ip, uint16_t port, char co
int main (int argc, char const *const *argv)
{
iopause_fd x[2] = { { .events = IOPAUSE_READ }, { .fd = 0, .events = IOPAUSE_READ | IOPAUSE_EXCEPT } } ;
- int flag1 = 0 ;
+ size_t m = 21 ;
+ uint16_t port ;
+ char ip[SKALIBS_IP_SIZE] ;
+ char modifs[sizeof("PROTO=TCP TCPLOCALIP= TCPLOCALPORT= TCPREMOTEIP= TCPREMOTEPORT= TCPCONNNUM=") + 2 * (IP46_FMT + UINT16_FMT) + UINT32_FMT] = "PROTO=TCP\0TCPLOCALIP=" ;
+ uint8_t flag1 = 0 ;
PROG = "s6-tcpserverd" ;
+
{
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
@@ -314,36 +319,65 @@ int main (int argc, char const *const *argv)
}
}
argc -= l.ind ; argv += l.ind ;
- if (!argc || !*argv[0]) dieusage() ;
- {
- struct stat st ;
- if (fstat(0, &st) < 0) strerr_diefu1sys(111, "fstat stdin") ;
- if (!S_ISSOCK(st.st_mode)) strerr_dief1x(100, "stdin is not a socket") ;
- }
- if (coe(0) == -1 || ndelay_on(0) == -1)
- strerr_diefu1sys(111, "set socket flags") ;
- if (!fd_ensure_open(1, 1)) strerr_diefu1sys(111, "sanitize stdout") ;
- if (!maxconn) maxconn = 1 ;
- if (maxconn > ABSOLUTE_MAXCONN) maxconn = ABSOLUTE_MAXCONN ;
- if (localmaxconn > maxconn) localmaxconn = maxconn ;
-
- x[0].fd = selfpipe_init() ;
- if (x[0].fd == -1) strerr_diefu1sys(111, "create selfpipe") ;
- if (!sig_altignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ;
+ }
+
+ if (!argc || !*argv[0]) dieusage() ;
+ {
+ struct stat st ;
+ if (fstat(0, &st) < 0) strerr_diefu1sys(111, "fstat stdin") ;
+ if (!S_ISSOCK(st.st_mode)) strerr_dief1x(100, "stdin is not a socket") ;
+ }
+ if (coe(0) == -1 || ndelay_on(0) == -1)
+ strerr_diefu1sys(111, "set socket flags") ;
+ if (!fd_ensure_open(1, 1)) strerr_diefu1sys(111, "sanitize stdout") ;
+ if (!maxconn) maxconn = 1 ;
+ if (maxconn > ABSOLUTE_MAXCONN) maxconn = ABSOLUTE_MAXCONN ;
+ if (localmaxconn > maxconn) localmaxconn = maxconn ;
+
+ x[0].fd = selfpipe_init() ;
+ if (x[0].fd == -1) strerr_diefu1sys(111, "create selfpipe") ;
+ if (!sig_altignore(SIGPIPE)) strerr_diefu1sys(111, "ignore SIGPIPE") ;
+ {
+ sigset_t set ;
+ sigemptyset(&set) ;
+ sigaddset(&set, SIGCHLD) ;
+ sigaddset(&set, SIGTERM) ;
+ sigaddset(&set, SIGHUP) ;
+ sigaddset(&set, SIGQUIT) ;
+ sigaddset(&set, SIGABRT) ;
+ if (!selfpipe_trapset(&set)) strerr_diefu1sys(111, "trap signals") ;
+ }
+ fmtmaxconn[1 + uint32_fmt(fmtmaxconn + 1, maxconn)] = 0 ;
+ fmtlocalmaxconn[1 + uint32_fmt(fmtlocalmaxconn + 1, localmaxconn)] = 0 ;
+
+ {
+ size_t ippos, portpos, portlen ;
+ ip46 loc ;
+ if (socket_local46(0, &loc, &port) == -1)
+ strerr_diefu1sys(111, "get local socket information") ;
+ is6 = ip46_is6(&loc) ;
+ memcpy(ip, loc.ip, is6 ? 16 : 4) ;
+ ippos = m ;
+ m += is6 ? ip6_fmt(modifs + m, ip) : ip4_fmt(modifs + m, ip) ;
+ memcpy(modifs + m, "\0TCPLOCALPORT=", 14) ; m += 14 ;
+ portpos = m ;
+ m += uint16_fmt(modifs + m, port) ;
+ portlen = m - portpos ;
+ memcpy(modifs + m, "\0TCPREMOTEIP=", 13) ; m += 13 ;
+
+ log_start(modifs + ippos, modifs + portpos) ;
+
+ if (flag1)
{
- sigset_t set ;
- sigemptyset(&set) ;
- sigaddset(&set, SIGCHLD) ;
- sigaddset(&set, SIGTERM) ;
- sigaddset(&set, SIGHUP) ;
- sigaddset(&set, SIGQUIT) ;
- sigaddset(&set, SIGABRT) ;
- if (!selfpipe_trapset(&set)) strerr_diefu1sys(111, "trap signals") ;
+ char fmtport[UINT16_FMT] ;
+ memcpy(fmtport, modifs + portpos, portlen) ;
+ fmtport[portlen] = '\n' ;
+ allwrite(1, fmtport, portlen + 1) ;
}
- fmtmaxconn[1 + uint32_fmt(fmtmaxconn + 1, maxconn)] = 0 ;
- fmtlocalmaxconn[1 + uint32_fmt(fmtlocalmaxconn + 1, localmaxconn)] = 0 ;
+ close(1) ;
}
+
{
/* Yo dawg, I herd u like stack allocations */
char ipnum_storage[maxconn * (is6 ? 20 : 8)] ;
@@ -359,10 +393,6 @@ int main (int argc, char const *const *argv)
avltreen byip_info ;
avltreen bypid_info ;
size_t envlen = env_len((char const *const *)environ) ;
- size_t m = 21 ;
- char ip[SKALIBS_IP_SIZE] ;
- uint16_t port ;
- char modifs[sizeof("PROTO=TCP TCPLOCALIP= TCPLOCALPORT= TCPREMOTEIP= TCPREMOTEPORT= TCPCONNNUM=") + 2 * (IP46_FMT + UINT16_FMT) + UINT32_FMT] = "PROTO=TCP\0TCPLOCALIP=" ;
genset_init(&ipnum_info, ipnum_storage, ipnum_freelist, is6 ? 20 : 8, maxconn) ;
GENSET_init(&pidi_info, pidi, pidi_storage, pidi_freelist, maxconn) ;
@@ -372,34 +402,7 @@ int main (int argc, char const *const *argv)
pidis = &pidi_info ;
by_ip = &byip_info ;
by_pid = &bypid_info ;
-
- {
- size_t ippos, portpos, portlen ;
- ip46 loc ;
- if (socket_local46(0, &loc, &port) == -1)
- strerr_diefu1sys(111, "get local socket information") ;
- is6 = ip46_is6(&loc) ;
- memcpy(ip, loc.ip, is6 ? 16 : 4) ;
- ippos = m ;
- m += is6 ? ip6_fmt(modifs + m, ip) : ip4_fmt(modifs + m, ip) ;
- memcpy(modifs + m, "\0TCPLOCALPORT=", 14) ; m += 14 ;
- portpos = m ;
- m += uint16_fmt(modifs + m, port) ;
- portlen = m - portpos ;
- memcpy(modifs + m, "\0TCPREMOTEIP=", 13) ; m += 13 ;
-
- log_start(modifs + ippos, modifs + portpos) ;
- log_status() ;
-
- if (flag1)
- {
- char fmtport[UINT16_FMT] ;
- memcpy(fmtport, modifs + portpos, portlen) ;
- fmtport[portlen] = '\n' ;
- allwrite(1, fmtport, portlen + 1) ;
- }
- close(1) ;
- }
+ log_status() ;
while (cont)
{