summaryrefslogtreecommitdiff
path: root/src/conn-tools
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-03-12 19:39:01 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-03-12 19:39:01 +0000
commit53091e3bce487ee82e2805a0231e780551561717 (patch)
treef0fa36ff8eadaf1f01d4510597b5e3a310764dc7 /src/conn-tools
parentf85b8a70f3b44510a5cf3895bf7357ae90655f65 (diff)
downloads6-networking-53091e3bce487ee82e2805a0231e780551561717.tar.xz
Adapt to skalibs-2.5.0.0
Diffstat (limited to 'src/conn-tools')
-rw-r--r--src/conn-tools/s6-getservbyname.c2
-rw-r--r--src/conn-tools/s6-ident-client.c7
-rw-r--r--src/conn-tools/s6-tcpclient.c36
-rw-r--r--src/conn-tools/s6-tcpserver-access.c65
-rw-r--r--src/conn-tools/s6-tcpserver.c22
-rw-r--r--src/conn-tools/s6-tcpserver4-socketbinder.c6
-rw-r--r--src/conn-tools/s6-tcpserver4.c22
-rw-r--r--src/conn-tools/s6-tcpserver4d.c75
-rw-r--r--src/conn-tools/s6-tcpserver6-socketbinder.c9
-rw-r--r--src/conn-tools/s6-tcpserver6.c22
-rw-r--r--src/conn-tools/s6-tcpserver6d.c78
-rw-r--r--src/conn-tools/s6-tlsc.c18
-rw-r--r--src/conn-tools/s6-tlsclient.c12
-rw-r--r--src/conn-tools/s6-tlsd.c18
-rw-r--r--src/conn-tools/s6-tlsserver.c30
15 files changed, 197 insertions, 225 deletions
diff --git a/src/conn-tools/s6-getservbyname.c b/src/conn-tools/s6-getservbyname.c
index a7ccc9d..0c60320 100644
--- a/src/conn-tools/s6-getservbyname.c
+++ b/src/conn-tools/s6-getservbyname.c
@@ -2,7 +2,7 @@
#include <stdint.h>
#include <netdb.h>
-#include <skalibs/uint16.h>
+#include <skalibs/types.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr2.h>
diff --git a/src/conn-tools/s6-ident-client.c b/src/conn-tools/s6-ident-client.c
index d4876ae..1d24904 100644
--- a/src/conn-tools/s6-ident-client.c
+++ b/src/conn-tools/s6-ident-client.c
@@ -2,8 +2,7 @@
#include <stdint.h>
#include <errno.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/buffer.h>
@@ -27,7 +26,7 @@ int main (int argc, char const *const *argv)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "t:", &l) ;
+ int opt = subgetopt_r(argc, argv, "t:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -56,7 +55,7 @@ int main (int argc, char const *const *argv)
{
char buf[BUFFER_OUTSIZE_SMALL] ;
- register int r = s6net_ident_client_g(buf, BUFFER_OUTSIZE_SMALL, &ra, rp, &la, lp, &deadline) ;
+ int r = s6net_ident_client_g(buf, BUFFER_OUTSIZE_SMALL, &ra, rp, &la, lp, &deadline) ;
if (r < 0) strerr_diefu1sys(errno == ETIMEDOUT ? 99 : 111, "s6net_ident_client") ;
else if (!r)
{
diff --git a/src/conn-tools/s6-tcpclient.c b/src/conn-tools/s6-tcpclient.c
index 3085e06..47be4a7 100644
--- a/src/conn-tools/s6-tcpclient.c
+++ b/src/conn-tools/s6-tcpclient.c
@@ -1,11 +1,9 @@
/* ISC license. */
-#include <sys/types.h>
+#include <string.h>
#include <stdint.h>
#include <errno.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
-#include <skalibs/bytestr.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/fmtscan.h>
#include <skalibs/strerr2.h>
@@ -65,7 +63,7 @@ int main (int argc, char const *const *argv)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, OPTSTRING, &l) ;
+ int opt = subgetopt_r(argc, argv, OPTSTRING, &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -119,8 +117,7 @@ int main (int argc, char const *const *argv)
{
ip46_t ip[2][MAXIP] ;
unsigned int j = 0 ;
- unsigned int n[2] = { 0, 0 } ;
- register unsigned int i = 0 ;
+ size_t n[2] = { 0, 0 } ;
if (!**argv || ((**argv == '0') && !argv[0][1]))
{
#ifdef SKALIBS_IPV6_ENABLED
@@ -136,14 +133,14 @@ int main (int argc, char const *const *argv)
if (flags.ip6 && !flags.ip4)
{
char ip6[MAXIP << 4] ;
- register unsigned int i = 0 ;
+ size_t i = 0 ;
if (!ip6_scanlist(ip6, MAXIP, argv[0], &n[0])) usage() ;
for (; i < n[0] ; i++) ip46_from_ip6(&ip[0][i], ip6 + (i << 4)) ;
}
else if (!flags.ip6)
{
char ip4[MAXIP << 2] ;
- register unsigned int i = 0 ;
+ size_t i = 0 ;
if (!ip4_scanlist(ip4, MAXIP, argv[0], &n[0])) usage() ;
for (; i < n[0] ; i++) ip46_from_ip4(&ip[0][i], ip4 + (i << 2)) ;
}
@@ -159,7 +156,8 @@ int main (int argc, char const *const *argv)
if (!ip46_scanlist(ip[0], MAXIP, argv[0], &n[0]))
{
genalloc ips = STRALLOC_ZERO ;
- if (s6dns_resolve_aaaaa_g(&ips, argv[0], str_len(argv[0]), flags.qualif, &deadline) <= 0)
+ size_t i = 0 ;
+ if (s6dns_resolve_aaaaa_g(&ips, argv[0], strlen(argv[0]), flags.qualif, &deadline) <= 0)
strerr_diefu4x(111, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
n[0] = genalloc_len(ip46_t, &ips) ;
if (n[0] >= MAXIP) n[0] = MAXIP ;
@@ -172,13 +170,14 @@ int main (int argc, char const *const *argv)
char ip6[MAXIP << 4] ;
if (ip6_scanlist(ip6, MAXIP, argv[0], &n[0]))
{
- register unsigned int i = 0 ;
+ size_t i = 0 ;
for (; i < n[0] ; i++) ip46_from_ip6(&ip[0][i], ip6 + (i << 4)) ;
}
else
{
stralloc ip6s = STRALLOC_ZERO ;
- if (s6dns_resolve_aaaa_g(&ip6s, argv[0], str_len(argv[0]), flags.qualif, &deadline) <= 0)
+ size_t i = 0 ;
+ if (s6dns_resolve_aaaa_g(&ip6s, argv[0], strlen(argv[0]), flags.qualif, &deadline) <= 0)
strerr_diefu4x(111, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
n[0] = ip6s.len >> 4 ;
if (n[0] >= MAXIP) n[0] = MAXIP ;
@@ -192,13 +191,14 @@ int main (int argc, char const *const *argv)
char ip4[MAXIP << 2] ;
if (ip4_scanlist(ip4, MAXIP, argv[0], &n[0]))
{
- register unsigned int i = 0 ;
+ size_t i = 0 ;
for (; i < n[0] ; i++) ip46_from_ip4(&ip[0][i], ip4 + (i << 2)) ;
}
else
{
stralloc ip4s = STRALLOC_ZERO ;
- if (s6dns_resolve_a_g(&ip4s, argv[0], str_len(argv[0]), flags.qualif, &deadline) <= 0)
+ size_t i = 0 ;
+ if (s6dns_resolve_a_g(&ip4s, argv[0], strlen(argv[0]), flags.qualif, &deadline) <= 0)
strerr_diefu4x(111, "resolve ", argv[0], ": ", s6dns_constants_error_str(errno)) ;
n[0] = ip4s.len >> 2 ;
if (n[0] >= MAXIP) n[0] = MAXIP ;
@@ -218,7 +218,7 @@ int main (int argc, char const *const *argv)
for (; j < 2 ; j++)
{
- unsigned int i = 0 ;
+ size_t i = 0 ;
for (; i < n[j] ; i++)
{
tain_t localdeadline ;
@@ -319,7 +319,7 @@ int main (int argc, char const *const *argv)
else
{
char s[256] ;
- register unsigned int len = 0 ;
+ unsigned int len = 0 ;
if (genalloc_len(s6dns_domain_t, &data[0].ds))
len = s6dns_domain_tostring(s, 255, genalloc_s(s6dns_domain_t, &data[0].ds)) ;
genalloc_free(s6dns_domain_t, &data[0].ds) ;
@@ -336,7 +336,7 @@ int main (int argc, char const *const *argv)
else
{
char s[256] ;
- register unsigned int len = 0 ;
+ unsigned int len = 0 ;
if (genalloc_len(s6dns_domain_t, &data[1].ds))
len = s6dns_domain_tostring(s, 255, genalloc_s(s6dns_domain_t, &data[1].ds)) ;
genalloc_free(s6dns_domain_t, &data[1].ds) ;
@@ -357,7 +357,7 @@ int main (int argc, char const *const *argv)
char idbuf[S6NET_IDENT_ID_SIZE] ;
if (flags.remoteinfo)
{
- register int r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &flags.localip, flags.localport, &deadline) ;
+ ssize_t r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &flags.localip, flags.localport, &deadline) ;
if (r <= 0)
{
if (flags.verbosity)
diff --git a/src/conn-tools/s6-tcpserver-access.c b/src/conn-tools/s6-tcpserver-access.c
index 72a3d2f..e16fe08 100644
--- a/src/conn-tools/s6-tcpserver-access.c
+++ b/src/conn-tools/s6-tcpserver-access.c
@@ -1,12 +1,11 @@
/* ISC license. */
-#include <sys/types.h>
+#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <skalibs/gccattributes.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
#include <skalibs/strerr2.h>
#include <skalibs/sgetopt.h>
#include <skalibs/buffer.h>
@@ -30,22 +29,22 @@
#define X() strerr_dief1x(101, "internal inconsistency. Please submit a bug-report.")
-static void logit (unsigned int pid, ip46_t const *ip, int h)
+static void logit (pid_t pid, ip46_t const *ip, int h)
{
- char fmtpid[UINT_FMT] ;
+ char fmtpid[PID_FMT] ;
char fmtip[IP46_FMT] ;
fmtip[ip46_fmt(fmtip, ip)] = 0 ;
- fmtpid[uint_fmt(fmtpid, pid)] = 0 ;
+ fmtpid[pid_fmt(fmtpid, pid)] = 0 ;
if (h) strerr_warni5x("allow", " pid ", fmtpid, " ip ", fmtip) ;
else strerr_warni5sys("deny", " pid ", fmtpid, " ip ", fmtip) ;
}
-static inline void log_accept (unsigned int pid, ip46_t const *ip)
+static inline void log_accept (pid_t pid, ip46_t const *ip)
{
logit(pid, ip, 1) ;
}
-static inline void log_deny (unsigned int pid, ip46_t const *ip)
+static inline void log_deny (pid_t pid, ip46_t const *ip)
{
logit(pid, ip, 0) ;
}
@@ -76,7 +75,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "WwDdHhRrPpv:l:B:t:i:x:", &l) ;
+ int opt = subgetopt_r(argc, argv, "WwDdHhRrPpv:l:B:t:i:x:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -94,8 +93,8 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'l' : localname = l.arg ; break ;
case 'B' :
{
- register size_t n = str_len(l.arg) ;
- if (buffer_putnoflush(buffer_1small, l.arg, n) < n)
+ size_t n = strlen(l.arg) ;
+ if (buffer_putnoflush(buffer_1small, l.arg, n) < (ssize_t)n)
strerr_dief1x(100, "banner too long") ;
break ;
}
@@ -114,16 +113,16 @@ int main (int argc, char const *const *argv, char const *const *envp)
proto = env_get2(envp, "PROTO") ;
if (!proto) strerr_dienotset(100, "PROTO") ;
- protolen = str_len(proto) ;
+ protolen = strlen(proto) ;
{
char const *x ;
char tmp[protolen + 11] ;
- byte_copy(tmp, protolen, proto) ;
- byte_copy(tmp + protolen, 9, "REMOTEIP") ;
+ memcpy(tmp, proto, protolen) ;
+ memcpy(tmp + protolen, "REMOTEIP", 9) ;
x = env_get2(envp, tmp) ;
if (!x) strerr_dienotset(100, tmp) ;
if (!ip46_scan(x, &remoteip)) strerr_dieinvalid(100, tmp) ;
- byte_copy(tmp + protolen + 6, 5, "PORT") ;
+ memcpy(tmp + protolen + 6, "PORT", 5) ;
x = env_get2(envp, tmp) ;
if (!x) strerr_dienotset(100, tmp) ;
if (!uint160_scan(x, &remoteport)) strerr_dieinvalid(100, tmp) ;
@@ -184,16 +183,16 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (socket_local46(0, &localip, &localport) < 0)
strerr_diefu1sys(111, "socket_local") ;
fmt[ip46_fmt(fmt, &localip)] = 0 ;
- byte_copy(tmp, protolen, proto) ;
- byte_copy(tmp + protolen, 8, "LOCALIP") ;
+ memcpy(tmp, proto, protolen) ;
+ memcpy(tmp + protolen, "LOCALIP", 8) ;
if (!env_addmodif(&modifs, tmp, fmt)) dienomem() ;
fmt[uint16_fmt(fmt, localport)] = 0 ;
- byte_copy(tmp + protolen + 5, 5, "PORT") ;
+ memcpy(tmp + protolen + 5, "PORT", 5) ;
if (!env_addmodif(&modifs, tmp, fmt)) dienomem() ;
- byte_copy(tmp + protolen, 11, "REMOTEINFO") ;
+ memcpy(tmp + protolen, "REMOTEINFO", 11) ;
if (flagident)
{
- register int r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &localip, localport, &deadline) ;
+ ssize_t r = s6net_ident_client_g(idbuf, S6NET_IDENT_ID_SIZE, &remoteip, remoteport, &localip, localport, &deadline) ;
if (r < 0)
{
if (verbosity >= 3) strerr_warnwu1sys("s6net_ident_client") ;
@@ -221,10 +220,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (!flagdnslookup)
{
char tmp[protolen + 11] ;
- byte_copy(tmp, protolen, proto) ;
- byte_copy(tmp + protolen, 10, "LOCALHOST") ;
+ memcpy(tmp, proto, protolen) ;
+ memcpy(tmp + protolen, "LOCALHOST", 10) ;
if (!env_addmodif(&modifs, tmp, localname)) dienomem() ;
- byte_copy(tmp + protolen, 11, "REMOTEHOST") ;
+ memcpy(tmp + protolen, "REMOTEHOST", 11) ;
if (!env_addmodif(&modifs, tmp, 0)) dienomem() ;
}
else
@@ -236,10 +235,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
unsigned int remotelen = 0 ;
char tcplocalhost[(protolen << 1) + 21] ;
char *tcpremotehost = tcplocalhost + protolen + 10 ;
- byte_copy(tcplocalhost, protolen, proto) ;
- byte_copy(tcplocalhost + protolen, 10, "LOCALHOST") ;
- byte_copy(tcpremotehost, protolen, proto) ;
- byte_copy(tcpremotehost + protolen, 11, "REMOTEHOST") ;
+ memcpy(tcplocalhost, proto, protolen) ;
+ memcpy(tcplocalhost + protolen, "LOCALHOST", 10) ;
+ memcpy(tcpremotehost, proto, protolen) ;
+ memcpy(tcpremotehost + protolen, "REMOTEHOST", 11) ;
if (!s6dns_init())
{
@@ -293,7 +292,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
else
{
char s[256] ;
- register unsigned int len = 0 ;
+ unsigned int len = 0 ;
if (genalloc_len(s6dns_domain_t, &data[0].ds))
{
s6dns_domain_noqualify(genalloc_s(s6dns_domain_t, &data[0].ds)) ;
@@ -314,7 +313,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
remotebuf[remotelen] = 0 ;
if (flagparanoid)
{
- register int r ;
+ int r ;
data[1].ds.len = 0 ;
r = ip46_is6(&remoteip) ? s6dns_resolve_aaaa_g(&data[1].ds, remotebuf, remotelen, 0, &deadline) : s6dns_resolve_a_g(&data[1].ds, remotebuf, remotelen, 0, &deadline) ;
if (r <= 0)
@@ -329,9 +328,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
else
{
- register unsigned int i = 0 ;
+ size_t i = 0 ;
for (; i < data[1].ds.len ; i += ip46_is6(&remoteip) ? 16 : 4)
- if (!byte_diff(remoteip.ip, ip46_is6(&remoteip) ? 16 : 4, data[1].ds.s + i)) break ;
+ if (!memcmp(remoteip.ip, data[1].ds.s + i, ip46_is6(&remoteip) ? 16 : 4)) break ;
if (i >= data[1].ds.len) remotelen = 0 ;
}
}
@@ -390,10 +389,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
reject:
if (verbosity >= 2)
{
- char fmtpid[UINT_FMT] ;
+ char fmtpid[PID_FMT] ;
char fmtip[IP46_FMT] ;
fmtip[ip46_fmt(fmtip, &remoteip)] = 0 ;
- fmtpid[uint_fmt(fmtpid, getpid())] = 0 ;
+ fmtpid[pid_fmt(fmtpid, getpid())] = 0 ;
strerr_dief5x(e, "reject", " pid ", fmtpid, " ip ", fmtip) ;
}
else return e ;
diff --git a/src/conn-tools/s6-tcpserver.c b/src/conn-tools/s6-tcpserver.c
index 3036ce7..3866b75 100644
--- a/src/conn-tools/s6-tcpserver.c
+++ b/src/conn-tools/s6-tcpserver.c
@@ -2,9 +2,7 @@
#include <sys/types.h>
#include <limits.h>
-#include <skalibs/uint64.h>
-#include <skalibs/uint.h>
-#include <skalibs/gidstuff.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
@@ -21,10 +19,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
int flag1 = 0 ;
int flagU = 0 ;
int flagreuse = 1 ;
- uint64 uid = 0 ;
+ uid_t uid = 0 ;
gid_t gid = 0 ;
gid_t gids[NGROUPS_MAX] ;
- unsigned int gidn = (unsigned int)-1 ;
+ size_t gidn = (size_t)-1 ;
unsigned int maxconn = 0 ;
unsigned int localmaxconn = 0 ;
unsigned int backlog = (unsigned int)-1 ;
@@ -34,7 +32,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "qQvDd1U46c:C:b:u:g:G:", &l) ;
+ int opt = subgetopt_r(argc, argv, "qQvDd1U46c:C:b:u:g:G:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -48,11 +46,11 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'c' : if (!uint0_scan(l.arg, &maxconn)) dieusage() ; if (!maxconn) maxconn = 1 ; break ;
case 'C' : if (!uint0_scan(l.arg, &localmaxconn)) dieusage() ; if (!localmaxconn) localmaxconn = 1 ; break ;
case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ;
- case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ;
+ case 'u' : if (!uid0_scan(l.arg, &uid)) dieusage() ; break ;
case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ;
case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ;
case '1' : flag1 = 1 ; break ;
- case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (unsigned int)-1 ; break ;
+ case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (size_t)-1 ; break ;
default : dieusage() ;
}
}
@@ -70,7 +68,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
size_t pos = 0 ;
unsigned int m = 0 ;
- char fmt[UINT_FMT * 3 + UINT64_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
+ char fmt[UINT_FMT * 3 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
char const *newargv[23 + argc] ;
newargv[m++] = what == 6 ? S6_NETWORKING_BINPREFIX "s6-tcpserver6-socketbinder" : S6_NETWORKING_BINPREFIX "s6-tcpserver4-socketbinder" ;
if (!flagreuse) newargv[m++] = "-D" ;
@@ -84,7 +82,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
newargv[m++] = "--" ;
newargv[m++] = *argv++ ;
newargv[m++] = *argv++ ;
- if (flagU || uid || gid || gidn != (unsigned int)-1)
+ if (flagU || uid || gid || gidn != (size_t)-1)
{
newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ;
if (flagU) newargv[m++] = "-Uz" ;
@@ -92,7 +90,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
newargv[m++] = "-u" ;
newargv[m++] = fmt + pos ;
- pos += uint64_fmt(fmt + pos, uid) ;
+ pos += uid_fmt(fmt + pos, uid) ;
fmt[pos++] = 0 ;
}
if (gid)
@@ -102,7 +100,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
pos += gid_fmt(fmt + pos, gid) ;
fmt[pos++] = 0 ;
}
- if (gidn != (unsigned int)-1)
+ if (gidn != (size_t)-1)
{
newargv[m++] = "-G" ;
newargv[m++] = fmt + pos ;
diff --git a/src/conn-tools/s6-tcpserver4-socketbinder.c b/src/conn-tools/s6-tcpserver4-socketbinder.c
index a15e5f1..cc97486 100644
--- a/src/conn-tools/s6-tcpserver4-socketbinder.c
+++ b/src/conn-tools/s6-tcpserver4-socketbinder.c
@@ -1,11 +1,9 @@
/* ISC license. */
-#include <sys/types.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/fmtscan.h>
#include <skalibs/strerr2.h>
@@ -27,7 +25,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ;
+ int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ;
if (opt == -1) break ;
switch (opt)
{
diff --git a/src/conn-tools/s6-tcpserver4.c b/src/conn-tools/s6-tcpserver4.c
index f0836d3..6860871 100644
--- a/src/conn-tools/s6-tcpserver4.c
+++ b/src/conn-tools/s6-tcpserver4.c
@@ -2,9 +2,7 @@
#include <sys/types.h>
#include <limits.h>
-#include <skalibs/uint64.h>
-#include <skalibs/uint.h>
-#include <skalibs/gidstuff.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
@@ -20,10 +18,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
int flag1 = 0 ;
int flagU = 0 ;
int flagreuse = 1 ;
- uint64 uid = 0 ;
+ uid_t uid = 0 ;
gid_t gid = 0 ;
gid_t gids[NGROUPS_MAX] ;
- unsigned int gidn = (unsigned int)-1 ;
+ size_t gidn = (size_t)-1 ;
unsigned int maxconn = 0 ;
unsigned int localmaxconn = 0 ;
unsigned int backlog = (unsigned int)-1 ;
@@ -32,7 +30,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ;
+ int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -42,11 +40,11 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'c' : if (!uint0_scan(l.arg, &maxconn)) dieusage() ; if (!maxconn) maxconn = 1 ; break ;
case 'C' : if (!uint0_scan(l.arg, &localmaxconn)) dieusage() ; if (!localmaxconn) localmaxconn = 1 ; break ;
case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ;
- case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ;
+ case 'u' : if (!uid0_scan(l.arg, &uid)) dieusage() ; break ;
case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ;
case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ;
case '1' : flag1 = 1 ; break ;
- case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (unsigned int)-1 ; break ;
+ case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (size_t)-1 ; break ;
default : dieusage() ;
}
}
@@ -57,7 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
size_t pos = 0 ;
unsigned int m = 0 ;
- char fmt[UINT_FMT * 4 + UINT64_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
+ char fmt[UINT_FMT * 4 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
char const *newargv[24 + argc] ;
newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver4-socketbinder" ;
if (!flagreuse) newargv[m++] = "-D" ;
@@ -72,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
newargv[m++] = "--" ;
newargv[m++] = *argv++ ;
newargv[m++] = *argv++ ;
- if (flagU || uid || gid || gidn != (unsigned int)-1)
+ if (flagU || uid || gid || gidn != (size_t)-1)
{
newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ;
if (flagU) newargv[m++] = "-Uz" ;
@@ -80,7 +78,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
newargv[m++] = "-u" ;
newargv[m++] = fmt + pos ;
- pos += uint64_fmt(fmt + pos, uid) ;
+ pos += uid_fmt(fmt + pos, uid) ;
fmt[pos++] = 0 ;
}
if (gid)
@@ -90,7 +88,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
pos += gid_fmt(fmt + pos, gid) ;
fmt[pos++] = 0 ;
}
- if (gidn != (unsigned int)-1)
+ if (gidn != (size_t)-1)
{
newargv[m++] = "-G" ;
newargv[m++] = fmt + pos ;
diff --git a/src/conn-tools/s6-tcpserver4d.c b/src/conn-tools/s6-tcpserver4d.c
index e176ee5..7579ea2 100644
--- a/src/conn-tools/s6-tcpserver4d.c
+++ b/src/conn-tools/s6-tcpserver4d.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <sys/types.h>
+#include <string.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -10,10 +10,7 @@
#include <signal.h>
#include <skalibs/gccattributes.h>
#include <skalibs/allreadwrite.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint32.h>
-#include <skalibs/uint.h>
-#include <skalibs/bytestr.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/fmtscan.h>
@@ -29,11 +26,18 @@
#define USAGE "s6-tcpserver4d [ -v verbosity ] [ -1 ] [ -c maxconn ] [ -C localmaxconn ] prog..."
+typedef struct pidip_s pidip_t, *pidip_t_ref ;
+struct pidip_s
+{
+ pid_t left ;
+ uint32_t right ;
+} ;
+
static unsigned int maxconn = 40 ;
static unsigned int localmaxconn = 40 ;
static unsigned int verbosity = 1 ;
static int cont = 1 ;
-static diuint32 *pidip = 0 ;
+static pidip_t *pidip = 0 ;
static unsigned int numconn = 0 ;
static diuint32 *ipnum = 0 ;
static unsigned int iplen = 0 ;
@@ -57,22 +61,18 @@ static inline void X (void)
/* Lookup primitives */
-static unsigned int lookup_diuint32 (diuint32 const *, unsigned int, unsigned int) gccattr_pure ;
-static unsigned int lookup_diuint32 (diuint32 const *tab, unsigned int tablen, unsigned int key)
+static inline unsigned int lookup_pid (pid_t pid)
{
- register unsigned int i = 0 ;
- for (; i < tablen ; i++) if (key == tab[i].left) break ;
+ unsigned int i = 0 ;
+ for (; i < numconn ; i++) if (pid == pidip[i].left) break ;
return i ;
}
-static inline unsigned int lookup_pid (uint32 pid)
-{
- return lookup_diuint32(pidip, numconn, pid) ;
-}
-
-static inline unsigned int lookup_ip (uint32 ip)
+static inline unsigned int lookup_ip (uint32_t ip)
{
- return lookup_diuint32(ipnum, iplen, ip) ;
+ unsigned int i = 0 ;
+ for (; i < iplen ; i++) if (ip == ipnum[i].left) break ;
+ return i ;
}
@@ -106,27 +106,27 @@ static void log_deny (uint32_t ip, uint16_t port, unsigned int num)
strerr_warni7sys("deny ", fmtip, ":", fmtport, " count ", fmtnum, fmtlocalmaxconn) ;
}
-static void log_accept (uint32_t pid, uint32_t ip, uint16_t port, unsigned int num)
+static void log_accept (pid_t pid, uint32_t ip, uint16_t port, unsigned int num)
{
char fmtipport[IP4_FMT + UINT16_FMT + 1] ;
- char fmtpid[UINT32_FMT] ;
+ char fmtpid[PID_FMT] ;
char fmtnum[UINT_FMT] ;
- register size_t n ;
+ size_t n ;
n = ip4_fmtu32(fmtipport, ip) ;
fmtipport[n++] = ':' ;
n += uint16_fmt(fmtipport + n, port) ;
fmtipport[n] = 0 ;
fmtnum[uint_fmt(fmtnum, num)] = 0 ;
- fmtpid[uint32_fmt(fmtpid, pid)] = 0 ;
+ fmtpid[pid_fmt(fmtpid, pid)] = 0 ;
strerr_warni7x("allow ", fmtipport, " pid ", fmtpid, " count ", fmtnum, fmtlocalmaxconn) ;
}
-static void log_close (uint32_t pid, uint32_t ip, int w)
+static void log_close (pid_t pid, uint32_t ip, int w)
{
- char fmtpid[UINT32_FMT] ;
+ char fmtpid[PID_FMT] ;
char fmtip[IP4_FMT] = "?" ;
char fmtw[UINT_FMT] ;
- fmtpid[uint32_fmt(fmtpid, pid)] = 0 ;
+ fmtpid[pid_fmt(fmtpid, pid)] = 0 ;
fmtip[ip4_fmtu32(fmtip, ip)] = 0 ;
fmtw[uint_fmt(fmtw, WIFSIGNALED(w) ? WTERMSIG(w) : WEXITSTATUS(w))] = 0 ;
strerr_warni6x("end pid ", fmtpid, " ip ", fmtip, WIFSIGNALED(w) ? " signal " : " exitcode ", fmtw) ;
@@ -137,7 +137,7 @@ static void log_close (uint32_t pid, uint32_t ip, int w)
static void killthem (int sig)
{
- register unsigned int i = 0 ;
+ unsigned int i = 0 ;
for (; i < numconn ; i++) kill(pidip[i].left, sig) ;
}
@@ -147,7 +147,7 @@ static void wait_children (void)
{
unsigned int i ;
int w ;
- register pid_t pid = wait_nohang(&w) ;
+ pid_t pid = wait_nohang(&w) ;
if (pid < 0)
if (errno != ECHILD) strerr_diefu1sys(111, "wait_nohang") ;
else break ;
@@ -156,7 +156,7 @@ static void wait_children (void)
if (i < numconn) /* it's one of ours ! */
{
uint32_t ip = pidip[i].right ;
- register unsigned int j = lookup_ip(ip) ;
+ unsigned int j = lookup_ip(ip) ;
if (j >= iplen) X() ;
if (!--ipnum[j].right) ipnum[j] = ipnum[--iplen] ;
pidip[i] = pidip[--numconn] ;
@@ -223,11 +223,11 @@ static void run_child (int s, uint32_t ip, uint16_t port, unsigned int num, char
PROG = "s6-tcpserver (child)" ;
if ((fd_move(0, s) < 0) || (fd_copy(1, 0) < 0))
strerr_diefu1sys(111, "move fds") ;
- byte_copy(fmt+n, 22, "PROTO=TCP\0TCPREMOTEIP=") ; n += 22 ;
+ memcpy(fmt+n, "PROTO=TCP\0TCPREMOTEIP=", 22) ; n += 22 ;
n += ip4_fmtu32(fmt+n, ip) ; fmt[n++] = 0 ;
- byte_copy(fmt+n, 14, "TCPREMOTEPORT=") ; n += 14 ;
+ memcpy(fmt+n, "TCPREMOTEPORT=", 14) ; n += 14 ;
n += uint16_fmt(fmt+n, port) ; fmt[n++] = 0 ;
- byte_copy(fmt+n, 11, "TCPCONNNUM=") ; n += 11 ;
+ memcpy(fmt+n, "TCPCONNNUM=", 11) ; n += 11 ;
n += uint_fmt(fmt+n, num) ; fmt[n++] = 0 ;
pathexec_r(argv, envp, env_len(envp), fmt, n) ;
strerr_dieexec(111, argv[0]) ;
@@ -237,7 +237,7 @@ static void new_connection (int s, uint32_t ip, uint16_t port, char const *const
{
unsigned int i = lookup_ip(ip) ;
unsigned int num = (i < iplen) ? ipnum[i].right : 0 ;
- register pid_t pid ;
+ pid_t pid ;
if (num >= localmaxconn)
{
log_deny(ip, port, num) ;
@@ -261,11 +261,11 @@ static void new_connection (int s, uint32_t ip, uint16_t port, char const *const
ipnum[iplen].left = ip ;
ipnum[iplen++].right = 1 ;
}
- pidip[numconn].left = (uint32_t)pid ;
+ pidip[numconn].left = pid ;
pidip[numconn++].right = ip ;
if (verbosity >= 2)
{
- log_accept((uint32_t)pid, ip, port, ipnum[i].right) ;
+ log_accept(pid, ip, port, ipnum[i].right) ;
log_status() ;
}
}
@@ -282,7 +282,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
int flag1 = 0 ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ;
+ int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -339,8 +339,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
{
- diuint32 inyostack[maxconn<<1] ;
- pidip = inyostack ; ipnum = inyostack + maxconn ;
+ pidip_t pidip_inyostack[maxconn] ;
+ diuint32 ipnum_inyostack[maxconn] ;
+ pidip = pidip_inyostack ; ipnum = ipnum_inyostack ;
while (cont)
{
if (iopause_g(x, 1 + (numconn < maxconn), 0) < 0)
@@ -355,7 +356,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
char packedip[4] ;
uint16_t port ;
- register int fd = socket_accept4(x[1].fd, packedip, &port) ;
+ int fd = socket_accept4(x[1].fd, packedip, &port) ;
if (fd < 0)
{
if (verbosity) strerr_warnwu1sys("accept") ;
diff --git a/src/conn-tools/s6-tcpserver6-socketbinder.c b/src/conn-tools/s6-tcpserver6-socketbinder.c
index e6c7fd8..4fc3ab4 100644
--- a/src/conn-tools/s6-tcpserver6-socketbinder.c
+++ b/src/conn-tools/s6-tcpserver6-socketbinder.c
@@ -1,10 +1,9 @@
/* ISC license. */
-#include <sys/types.h>
+#include <stdint.h>
#include <unistd.h>
#include <sys/socket.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/fmtscan.h>
#include <skalibs/strerr2.h>
@@ -20,13 +19,13 @@ int main (int argc, char const *const *argv, char const *const *envp)
int flagreuse = 1 ;
int flagudp = 0 ;
char ip[16] ;
- uint16 port ;
+ uint16_t port ;
PROG = "s6-tcpserver6-socketbinder" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ;
+ int opt = subgetopt_r(argc, argv, "DdMmb:", &l) ;
if (opt == -1) break ;
switch (opt)
{
diff --git a/src/conn-tools/s6-tcpserver6.c b/src/conn-tools/s6-tcpserver6.c
index d48efe1..8648e8e 100644
--- a/src/conn-tools/s6-tcpserver6.c
+++ b/src/conn-tools/s6-tcpserver6.c
@@ -2,9 +2,7 @@
#include <sys/types.h>
#include <limits.h>
-#include <skalibs/uint64.h>
-#include <skalibs/uint.h>
-#include <skalibs/gidstuff.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
@@ -20,10 +18,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
int flag1 = 0 ;
int flagU = 0 ;
int flagreuse = 1 ;
- uint64 uid = 0 ;
+ uid_t uid = 0 ;
gid_t gid = 0 ;
gid_t gids[NGROUPS_MAX] ;
- unsigned int gidn = (unsigned int)-1 ;
+ size_t gidn = (size_t)-1 ;
unsigned int maxconn = 0 ;
unsigned int localmaxconn = 0 ;
unsigned int backlog = (unsigned int)-1 ;
@@ -32,7 +30,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ;
+ int opt = subgetopt_r(argc, argv, "Dd1Uv:c:C:b:u:g:G:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -42,11 +40,11 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'c' : if (!uint0_scan(l.arg, &maxconn)) dieusage() ; if (!maxconn) maxconn = 1 ; break ;
case 'C' : if (!uint0_scan(l.arg, &localmaxconn)) dieusage() ; if (!localmaxconn) localmaxconn = 1 ; break ;
case 'b' : if (!uint0_scan(l.arg, &backlog)) dieusage() ; break ;
- case 'u' : if (!uint640_scan(l.arg, &uid)) dieusage() ; break ;
+ case 'u' : if (!uid0_scan(l.arg, &uid)) dieusage() ; break ;
case 'g' : if (!gid0_scan(l.arg, &gid)) dieusage() ; break ;
case 'G' : if (!gid_scanlist(gids, NGROUPS_MAX, l.arg, &gidn) && *l.arg) dieusage() ; break ;
case '1' : flag1 = 1 ; break ;
- case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (unsigned int)-1 ; break ;
+ case 'U' : flagU = 1 ; uid = 0 ; gid = 0 ; gidn = (size_t)-1 ; break ;
default : dieusage() ;
}
}
@@ -57,7 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
size_t pos = 0 ;
unsigned int m = 0 ;
- char fmt[UINT_FMT * 4 + UINT64_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
+ char fmt[UINT_FMT * 4 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
char const *newargv[24 + argc] ;
newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver6-socketbinder" ;
if (!flagreuse) newargv[m++] = "-D" ;
@@ -72,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
newargv[m++] = "--" ;
newargv[m++] = *argv++ ;
newargv[m++] = *argv++ ;
- if (flagU || uid || gid || gidn != (unsigned int)-1)
+ if (flagU || uid || gid || gidn != (size_t)-1)
{
newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ;
if (flagU) newargv[m++] = "-Uz" ;
@@ -80,7 +78,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
newargv[m++] = "-u" ;
newargv[m++] = fmt + pos ;
- pos += uint64_fmt(fmt + pos, uid) ;
+ pos += uid_fmt(fmt + pos, uid) ;
fmt[pos++] = 0 ;
}
if (gid)
@@ -90,7 +88,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
pos += gid_fmt(fmt + pos, gid) ;
fmt[pos++] = 0 ;
}
- if (gidn != (unsigned int)-1)
+ if (gidn != (size_t)-1)
{
newargv[m++] = "-G" ;
newargv[m++] = fmt + pos ;
diff --git a/src/conn-tools/s6-tcpserver6d.c b/src/conn-tools/s6-tcpserver6d.c
index 5079d2e..ec45322 100644
--- a/src/conn-tools/s6-tcpserver6d.c
+++ b/src/conn-tools/s6-tcpserver6d.c
@@ -1,6 +1,6 @@
/* ISC license. */
-#include <sys/types.h>
+#include <string.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/wait.h>
@@ -10,9 +10,7 @@
#include <signal.h>
#include <skalibs/gccattributes.h>
#include <skalibs/allreadwrite.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
-#include <skalibs/bytestr.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/fmtscan.h>
@@ -27,21 +25,27 @@
#define USAGE "s6-tcpserver6d [ -v verbosity ] [ -1 ] [ -c maxconn ] [ -C localmaxconn ] prog..."
+typedef struct pidip_s pidip_t, *pidip_t_ref ;
+struct pidip_s
+{
+ pid_t pid ;
+ char ip[16] ;
+} ;
+
typedef struct ipnum_s ipnum_t, *ipnum_t_ref ;
struct ipnum_s
{
char ip[16] ;
unsigned int num ;
} ;
-#define IPNUM_ZERO { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 0 }
static unsigned int maxconn = 40 ;
static unsigned int localmaxconn = 40 ;
static unsigned int verbosity = 1 ;
static int cont = 1 ;
-static ipnum_t_ref pidip = 0 ;
+static pidip_t *pidip = 0 ;
static unsigned int numconn = 0 ;
-static ipnum_t_ref ipnum = 0 ;
+static ipnum_t *ipnum = 0 ;
static unsigned int iplen = 0 ;
static char fmtmaxconn[UINT_FMT+1] = "/" ;
@@ -63,17 +67,17 @@ static inline void X (void)
/* Lookup primitives */
-static unsigned int lookup_pid (unsigned int pid)
+static inline unsigned int lookup_pid (pid_t pid)
{
- register unsigned int i = 0 ;
- for (; i < numconn ; i++) if (pid == pidip[i].num) break ;
+ unsigned int i = 0 ;
+ for (; i < numconn ; i++) if (pid == pidip[i].pid) break ;
return i ;
}
-static unsigned int lookup_ip (char const *ip)
+static inline unsigned int lookup_ip (char const *ip)
{
- register unsigned int i = 0 ;
- for (; i < iplen ; i++) if (!byte_diff(ip, 16, ipnum[i].ip)) break ;
+ unsigned int i = 0 ;
+ for (; i < iplen ; i++) if (!memcmp(ip, ipnum[i].ip, 16)) break ;
return i ;
}
@@ -108,27 +112,27 @@ static void log_deny (char const *ip, uint16_t port, unsigned int num)
strerr_warni7sys("deny ", fmtip, " port ", fmtport, " count ", fmtnum, fmtlocalmaxconn) ;
}
-static void log_accept (unsigned int pid, char const *ip, uint16_t port, unsigned int num)
+static void log_accept (pid_t pid, char const *ip, uint16_t port, unsigned int num)
{
char fmtipport[IP6_FMT + UINT16_FMT + 6] ;
- char fmtpid[UINT_FMT] ;
+ char fmtpid[PID_FMT] ;
char fmtnum[UINT_FMT] ;
- register size_t n ;
+ size_t n ;
n = ip6_fmt(fmtipport, ip) ;
- byte_copy(fmtipport + n, 6, " port ") ; n += 6 ;
+ memcpy(fmtipport + n, " port ", 6) ; n += 6 ;
n += uint16_fmt(fmtipport + n, port) ;
fmtipport[n] = 0 ;
fmtnum[uint_fmt(fmtnum, num)] = 0 ;
- fmtpid[uint_fmt(fmtpid, pid)] = 0 ;
+ fmtpid[pid_fmt(fmtpid, pid)] = 0 ;
strerr_warni7x("allow ", fmtipport, " pid ", fmtpid, " count ", fmtnum, fmtlocalmaxconn) ;
}
-static void log_close (unsigned int pid, char const *ip, int w)
+static void log_close (pid_t pid, char const *ip, int w)
{
- char fmtpid[UINT_FMT] ;
+ char fmtpid[PID_FMT] ;
char fmtip[IP6_FMT] = "?" ;
char fmtw[UINT_FMT] ;
- fmtpid[uint_fmt(fmtpid, pid)] = 0 ;
+ fmtpid[pid_fmt(fmtpid, pid)] = 0 ;
fmtip[ip6_fmt(fmtip, ip)] = 0 ;
fmtw[uint_fmt(fmtw, WIFSIGNALED(w) ? WTERMSIG(w) : WEXITSTATUS(w))] = 0 ;
strerr_warni6x("end pid ", fmtpid, " ip ", fmtip, WIFSIGNALED(w) ? " signal " : " exitcode ", fmtw) ;
@@ -139,8 +143,8 @@ static void log_close (unsigned int pid, char const *ip, int w)
static void killthem (int sig)
{
- register unsigned int i = 0 ;
- for (; i < numconn ; i++) kill(pidip[i].num, sig) ;
+ unsigned int i = 0 ;
+ for (; i < numconn ; i++) kill(pidip[i].pid, sig) ;
}
static void wait_children (void)
@@ -149,7 +153,7 @@ static void wait_children (void)
{
unsigned int i ;
int w ;
- register pid_t pid = wait_nohang(&w) ;
+ pid_t pid = wait_nohang(&w) ;
if (pid < 0)
if (errno != ECHILD) strerr_diefu1sys(111, "wait_nohang") ;
else break ;
@@ -157,7 +161,7 @@ static void wait_children (void)
i = lookup_pid(pid) ;
if (i < numconn) /* it's one of ours ! */
{
- register unsigned int j = lookup_ip(pidip[i].ip) ;
+ unsigned int j = lookup_ip(pidip[i].ip) ;
if (j >= iplen) X() ;
if (!--ipnum[j].num) ipnum[j] = ipnum[--iplen] ;
--numconn ;
@@ -225,11 +229,11 @@ static void run_child (int s, char const *ip, uint16_t port, unsigned int num, c
PROG = "s6-tcpserver6 (child)" ;
if ((fd_move(0, s) < 0) || (fd_copy(1, 0) < 0))
strerr_diefu1sys(111, "move fds") ;
- byte_copy(fmt+n, 24, "PROTO=TCP\0TCPREMOTEIP=") ; n += 22 ;
+ memcpy(fmt+n, "PROTO=TCP\0TCPREMOTEIP=", 24) ; n += 22 ;
n += ip6_fmt(fmt+n, ip) ; fmt[n++] = 0 ;
- byte_copy(fmt+n, 14, "TCPREMOTEPORT=") ; n += 14 ;
+ memcpy(fmt+n, "TCPREMOTEPORT=", 14) ; n += 14 ;
n += uint16_fmt(fmt+n, port) ; fmt[n++] = 0 ;
- byte_copy(fmt+n, 11, "TCPCONNNUM=") ; n += 11 ;
+ memcpy(fmt+n, "TCPCONNNUM=", 11) ; n += 11 ;
n += uint_fmt(fmt+n, num) ; fmt[n++] = 0 ;
pathexec_r(argv, envp, env_len(envp), fmt, n) ;
strerr_dieexec(111, argv[0]) ;
@@ -239,7 +243,7 @@ static void new_connection (int s, char const *ip, uint16_t port, char const *co
{
unsigned int i = lookup_ip(ip) ;
unsigned int num = (i < iplen) ? ipnum[i].num : 0 ;
- register pid_t pid ;
+ pid_t pid ;
if (num >= localmaxconn)
{
log_deny(ip, port, num) ;
@@ -260,11 +264,11 @@ static void new_connection (int s, char const *ip, uint16_t port, char const *co
if (i < iplen) ipnum[i].num = num + 1 ;
else
{
- byte_copy(ipnum[iplen].ip, 16, ip) ;
+ memcpy(ipnum[iplen].ip, ip, 16) ;
ipnum[iplen++].num = 1 ;
}
- pidip[numconn].num = pid ;
- byte_copy(pidip[numconn++].ip, 16, ip) ;
+ pidip[numconn].pid = pid ;
+ memcpy(pidip[numconn++].ip, ip, 16) ;
if (verbosity >= 2)
{
log_accept(pid, ip, port, ipnum[i].num) ;
@@ -282,7 +286,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
int flag1 = 0 ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ;
+ int opt = subgetopt_r(argc, argv, "1c:C:v:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -339,8 +343,10 @@ int main (int argc, char const *const *argv, char const *const *envp)
}
{
- ipnum_t inyostack[maxconn<<1] ;
- pidip = inyostack ; ipnum = inyostack + maxconn ;
+ pidip_t pidip_inyostack[maxconn] ;
+ ipnum_t ipnum_inyostack[maxconn] ;
+ pidip = pidip_inyostack ; ipnum = ipnum_inyostack ;
+
while (cont)
{
if (iopause_g(x, 1 + (numconn < maxconn), 0) < 0)
@@ -355,7 +361,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
char ip[16] ;
uint16_t port ;
- register int fd = socket_accept6(x[1].fd, ip, &port) ;
+ int fd = socket_accept6(x[1].fd, ip, &port) ;
if (fd < 0)
{
if (verbosity) strerr_warnwu1sys("accept") ;
diff --git a/src/conn-tools/s6-tlsc.c b/src/conn-tools/s6-tlsc.c
index 3e355f1..fb7272f 100644
--- a/src/conn-tools/s6-tlsc.c
+++ b/src/conn-tools/s6-tlsc.c
@@ -3,9 +3,7 @@
#include <sys/types.h>
#include <stdint.h>
#include <errno.h>
-#include <skalibs/uint64.h>
-#include <skalibs/uint.h>
-#include <skalibs/gidstuff.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/tai.h>
@@ -52,7 +50,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
unsigned int t = 0 ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "SsYyv:K:k:Zz6:7:", &l) ;
+ int opt = subgetopt_r(argc, argv, "SsYyv:K:k:Zz6:7:", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -90,17 +88,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (!getuid())
{
char const *x = env_get2(envp, "TLS_UID") ;
- if (x)
- {
- uint64 u ;
- if (!uint640_scan(x, &u)) strerr_dieinvalid(100, "TLS_UID") ;
- uid = (uid_t)u ;
- }
+ if (x && !uid0_scan(x, &uid)) strerr_dieinvalid(100, "TLS_UID") ;
x = env_get2(envp, "TLS_GID") ;
- if (x)
- {
- if (!gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ;
- }
+ if (x && !gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ;
}
return s6tlsc(argv, envp, &tto, preoptions, options, uid, gid, verbosity, servername, fds) ;
diff --git a/src/conn-tools/s6-tlsclient.c b/src/conn-tools/s6-tlsclient.c
index eb5311d..5bcc7e7 100644
--- a/src/conn-tools/s6-tlsclient.c
+++ b/src/conn-tools/s6-tlsclient.c
@@ -1,10 +1,8 @@
/* ISC license. */
-#include <sys/types.h>
+#include <string.h>
#include <stdint.h>
-#include <skalibs/uint16.h>
-#include <skalibs/uint.h>
-#include <skalibs/bytestr.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
@@ -72,7 +70,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "qQv46DdHhRrnNt:l:T:i:p:SsYyK:k:Zz", &l) ;
+ int opt = subgetopt_r(argc, argv, "qQv46DdHhRrnNt:l:T:i:p:SsYyK:k:Zz", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -93,7 +91,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'l' : o.localname = l.arg ; break ;
case 'T' :
{
- unsigned int n = uint_scan(l.arg, &o.ximeout) ;
+ size_t n = uint_scan(l.arg, &o.ximeout) ;
if (!n) dieusage() ;
o.doxy = 1 ;
if (!l.arg[n])
@@ -163,7 +161,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
pos += uint_fmt(fmt + pos, o.yimeout) ;
fmt[pos++] = 0 ;
}
- if (byte_diff(o.localip.ip, 16, IP6_ANY))
+ if (memcmp(o.localip.ip, IP6_ANY, 16))
{
newargv[m++] = "-i" ;
newargv[m++] = fmt + pos ;
diff --git a/src/conn-tools/s6-tlsd.c b/src/conn-tools/s6-tlsd.c
index da90179..d76b423 100644
--- a/src/conn-tools/s6-tlsd.c
+++ b/src/conn-tools/s6-tlsd.c
@@ -2,9 +2,7 @@
#include <sys/types.h>
#include <stdint.h>
-#include <skalibs/uint64.h>
-#include <skalibs/uint.h>
-#include <skalibs/gidstuff.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/tai.h>
@@ -49,7 +47,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
unsigned int t = 0 ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ;
+ int opt = subgetopt_r(argc, argv, "SsYyv:K:Zz", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -72,17 +70,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (!getuid())
{
char const *x = env_get2(envp, "TLS_UID") ;
- if (x)
- {
- uint64 u ;
- if (!uint640_scan(x, &u)) strerr_dieinvalid(100, "TLS_UID") ;
- uid = (uid_t)u ;
- }
+ if (x && !uid0_scan(x, &uid)) strerr_dieinvalid(100, "TLS_UID") ;
x = env_get2(envp, "TLS_GID") ;
- if (x)
- {
- if (!gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ;
- }
+ if (x && !gid0_scan(x, &gid)) strerr_dieinvalid(100, "TLS_GID") ;
}
return s6tlsd(argv, envp, &tto, preoptions, options, uid, gid, verbosity) ;
diff --git a/src/conn-tools/s6-tlsserver.c b/src/conn-tools/s6-tlsserver.c
index 82f857a..d6c84f5 100644
--- a/src/conn-tools/s6-tlsserver.c
+++ b/src/conn-tools/s6-tlsserver.c
@@ -2,9 +2,7 @@
#include <sys/types.h>
#include <limits.h>
-#include <skalibs/uint64.h>
-#include <skalibs/uint.h>
-#include <skalibs/gidstuff.h>
+#include <skalibs/types.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/djbunix.h>
@@ -21,16 +19,16 @@
typedef struct options_s options_t, *options_t_ref ;
struct options_s
{
- uint64 uid ;
char const *localname ;
char const *banner ;
char const *rules ;
gid_t gids[NGROUPS_MAX] ;
+ size_t gidn ;
+ uid_t uid ;
gid_t gid ;
unsigned int maxconn ;
unsigned int localmaxconn ;
unsigned int backlog ;
- unsigned int gidn ;
unsigned int timeout ;
unsigned int kimeout ;
unsigned int verbosity : 2 ;
@@ -52,15 +50,15 @@ struct options_s
#define OPTIONS_ZERO \
{ \
- .uid = 0, \
.localname = 0, \
.banner = 0, \
.rules = 0, \
- .maxconn = 0, \
- .localmaxconn = 0, \
.backlog = (unsigned int)-1, \
- .gidn = (unsigned int)-1, \
+ .gidn = (size_t)-1, \
+ .uid = 0, \
.gid = 0, \
+ .maxconn = 0, \
+ .localmaxconn = 0, \
.timeout = 0, \
.kimeout = 0, \
.verbosity = 1, \
@@ -88,7 +86,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- register int opt = subgetopt_r(argc, argv, "qQv461c:C:b:G:g:u:UWwDdHhRrPpl:B:t:i:x:SsYyK:Zz", &l) ;
+ int opt = subgetopt_r(argc, argv, "qQv461c:C:b:G:g:u:UWwDdHhRrPpl:B:t:i:x:SsYyK:Zz", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -102,9 +100,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'C' : if (!uint0_scan(l.arg, &o.localmaxconn)) dieusage() ; if (!o.localmaxconn) o.localmaxconn = 1 ; break ;
case 'b' : if (!uint0_scan(l.arg, &o.backlog)) dieusage() ; break ;
case 'G' : if (!gid_scanlist(o.gids, NGROUPS_MAX, l.arg, &o.gidn) && *l.arg) dieusage() ; o.doapply = 1 ; break ;
- case 'g' : if (!uint0_scan(l.arg, &o.gid)) dieusage() ; o.doapply = 1 ; break ;
- case 'u' : if (!uint0_scan(l.arg, &o.uid)) dieusage() ; o.doapply = 1 ; break ;
- case 'U' : o.flagU = 1 ; o.uid = 0 ; o.gid = 0 ; o.gidn = (unsigned int)-1 ; o.doapply = 1 ; break ;
+ case 'g' : if (!gid0_scan(l.arg, &o.gid)) dieusage() ; o.doapply = 1 ; break ;
+ case 'u' : if (!uid0_scan(l.arg, &o.uid)) dieusage() ; o.doapply = 1 ; break ;
+ case 'U' : o.flagU = 1 ; o.uid = 0 ; o.gid = 0 ; o.gidn = (size_t)-1 ; o.doapply = 1 ; break ;
case 'W' : o.flagw = 0 ; break ;
case 'w' : o.flagw = 1 ; break ;
case 'D' : o.flagD = 1 ; o.doaccess = 1 ; break ;
@@ -137,7 +135,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
size_t pos = 0 ;
unsigned int m = 0 ;
- char fmt[UINT_FMT * 5 + GID_FMT * (NGROUPS_MAX + 1) + UINT64_FMT] ;
+ char fmt[UINT_FMT * 5 + UID_FMT + GID_FMT * (NGROUPS_MAX + 1)] ;
char const *newargv[45 + argc] ;
newargv[m++] = S6_NETWORKING_BINPREFIX "s6-tcpserver" ;
if (o.verbosity != 1) newargv[m++] = o.verbosity ? "-v" : "-q" ;
@@ -218,7 +216,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
if (o.doapply)
{
newargv[m++] = S6_EXTBINPREFIX "s6-applyuidgid" ;
- if (o.gidn != (unsigned int)-1)
+ if (o.gidn != (size_t)-1)
{
newargv[m++] = "-G" ;
newargv[m++] = fmt + pos ;
@@ -236,7 +234,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
{
newargv[m++] = "-u" ;
newargv[m++] = fmt + pos ;
- pos += uint64_fmt(fmt + pos, o.uid) ;
+ pos += uid_fmt(fmt + pos, o.uid) ;
fmt[pos++] = 0 ;
}
if (o.flagU) newargv[m++] = "-Uz" ;