diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/conn-tools/s6-tcpserver4d.c | 13 | ||||
-rw-r--r-- | src/conn-tools/s6-tcpserver6d.c | 13 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/conn-tools/s6-tcpserver4d.c b/src/conn-tools/s6-tcpserver4d.c index 914e981..3432236 100644 --- a/src/conn-tools/s6-tcpserver4d.c +++ b/src/conn-tools/s6-tcpserver4d.c @@ -10,6 +10,7 @@ #include <signal.h> #include <skalibs/gccattributes.h> #include <skalibs/allreadwrite.h> +#include <skalibs/uint16.h> #include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> @@ -333,7 +334,17 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (flag1) { - fd_write(1, "\n", 1) ; + uint16_t port ; + uint16_t m = 0 ; + char ip[4] ; + char fmtport[UINT16_FMT] ; + if (socket_local4(0, ip, &port) == -1) + { + if (verbosity) strerr_warnwu1sys("socket_local4") ; + } + else m = uint16_fmt(fmtport, port) ; + fmtport[m++] = '\n' ; + allwrite(1, fmtport, m) ; fd_close(1) ; } } diff --git a/src/conn-tools/s6-tcpserver6d.c b/src/conn-tools/s6-tcpserver6d.c index 5a763b5..8000531 100644 --- a/src/conn-tools/s6-tcpserver6d.c +++ b/src/conn-tools/s6-tcpserver6d.c @@ -10,6 +10,7 @@ #include <signal.h> #include <skalibs/gccattributes.h> #include <skalibs/allreadwrite.h> +#include <skalibs/uint16.h> #include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> @@ -330,7 +331,17 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (flag1) { - fd_write(1, "\n", 1) ; + uint16_t port ; + uint16_t m = 0 ; + char ip[16] ; + char fmtport[UINT16_FMT] ; + if (socket_local6(0, ip, &port) == -1) + { + if (verbosity) strerr_warnwu1sys("socket_local6") ; + } + else m = uint16_fmt(fmtport, port) ; + fmtport[m++] = '\n' ; + allwrite(1, fmtport, m) ; fd_close(1) ; } fmtlocalmaxconn[1+uint_fmt(fmtlocalmaxconn+1, localmaxconn)] = 0 ; |