summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/skalibs/fmtscan.h7
-rw-r--r--src/libstddjb/iopause_poll.c8
-rw-r--r--src/libstddjb/iopause_ppoll.c8
-rw-r--r--src/libstddjb/iopause_select.c32
-rw-r--r--src/libstddjb/ip4_netmask.c14
-rw-r--r--src/libstddjb/ip6_netmask.c26
-rw-r--r--src/libunixonacid/unixmessage_bits_closeall.c10
7 files changed, 76 insertions, 29 deletions
diff --git a/src/include/skalibs/fmtscan.h b/src/include/skalibs/fmtscan.h
index a0d654c..bcd727c 100644
--- a/src/include/skalibs/fmtscan.h
+++ b/src/include/skalibs/fmtscan.h
@@ -29,7 +29,6 @@ extern size_t ip6_fmt (char *, char const *) ;
/* scan */
-
extern unsigned char fmtscan_num (unsigned char, unsigned char) gccattr_const ;
extern size_t ip4_scan (char const *, char *) ;
@@ -43,4 +42,10 @@ extern size_t ucharn_scan (char const *, char *, size_t) ;
extern size_t ucharn_scan_little (char const *, char *, size_t) ;
extern size_t ucharn_findlen (char const *) gccattr_pure ;
+
+ /* misc */
+
+extern int ip4_netmask (char *, uint8_t) ;
+extern int ip6_netmask (char *, uint8_t) ;
+
#endif
diff --git a/src/libstddjb/iopause_poll.c b/src/libstddjb/iopause_poll.c
index 0c7c681..f189974 100644
--- a/src/libstddjb/iopause_poll.c
+++ b/src/libstddjb/iopause_poll.c
@@ -8,6 +8,7 @@
int iopause_poll (iopause_fd *x, unsigned int len, tain const *deadline, tain const *stamp)
{
+ int r ;
int millisecs = 0 ;
if (!deadline) millisecs = -1 ;
else if (tain_less(stamp, deadline))
@@ -16,5 +17,10 @@ int iopause_poll (iopause_fd *x, unsigned int len, tain const *deadline, tain co
tain_sub(&t, deadline, stamp) ;
millisecs = tain_to_millisecs(&t) ;
}
- return poll(x, len, millisecs) ;
+ r = poll(x, len, millisecs) ;
+ if (r > 0)
+ for (unsigned int i = 0 ; i < len ; i++)
+ if (x[i].revents & IOPAUSE_EXCEPT)
+ x[i].revents |= x[i].events ;
+ return r ;
}
diff --git a/src/libstddjb/iopause_ppoll.c b/src/libstddjb/iopause_ppoll.c
index 336bf8e..6194d17 100644
--- a/src/libstddjb/iopause_ppoll.c
+++ b/src/libstddjb/iopause_ppoll.c
@@ -13,6 +13,7 @@
int iopause_ppoll (iopause_fd *x, unsigned int len, tain const *deadline, tain const *stamp)
{
+ int r ;
struct timespec ts = { .tv_sec = 0, .tv_nsec = 0 } ;
if (deadline && tain_less(stamp, deadline))
{
@@ -24,7 +25,12 @@ int iopause_ppoll (iopause_fd *x, unsigned int len, tain const *deadline, tain c
else deadline = 0 ;
}
}
- return ppoll(x, len, deadline ? &ts : 0, 0) ;
+ r = ppoll(x, len, deadline ? &ts : 0, 0) ;
+ if (r > 0)
+ for (unsigned int i = 0 ; i < len ; i++)
+ if (x[i].revents & IOPAUSE_EXCEPT)
+ x[i].revents |= x[i].events ;
+ return r ;
}
#else
diff --git a/src/libstddjb/iopause_select.c b/src/libstddjb/iopause_select.c
index f2deba2..09d007a 100644
--- a/src/libstddjb/iopause_select.c
+++ b/src/libstddjb/iopause_select.c
@@ -31,37 +31,31 @@ int iopause_select (iopause_fd *x, unsigned int len, tain const *deadline, tain
}
}
+ for (unsigned int i = 0 ; i < len ; i++)
{
- unsigned int i = 0 ;
- for (; i < len ; i++)
+ x[i].revents = 0 ;
+ if (x[i].fd >= 0)
{
- x[i].revents = 0 ;
- if (x[i].fd >= 0)
- {
- if (x[i].fd >= FD_SETSIZE) return (errno = EMFILE, -1) ;
- if (x[i].fd >= nfds) nfds = x[i].fd + 1 ;
- if (x[i].events & IOPAUSE_READ) FD_SET(x[i].fd, &rfds) ;
- if (x[i].events & IOPAUSE_WRITE) FD_SET(x[i].fd, &wfds) ;
- if (x[i].events & IOPAUSE_EXCEPT) FD_SET(x[i].fd, &xfds) ;
- }
+ if (x[i].fd >= FD_SETSIZE) return (errno = EMFILE, -1) ;
+ if (x[i].fd >= nfds) nfds = x[i].fd + 1 ;
+ if (x[i].events & IOPAUSE_READ) FD_SET(x[i].fd, &rfds) ;
+ if (x[i].events & IOPAUSE_WRITE) FD_SET(x[i].fd, &wfds) ;
+ if (x[i].events & IOPAUSE_EXCEPT) FD_SET(x[i].fd, &xfds) ;
}
}
r = select(nfds, &rfds, &wfds, &xfds, deadline ? &tv : 0) ;
if (r > 0)
- {
- unsigned int i = 0 ;
- for (; i < len ; i++) if (x[i].fd >= 0)
+ for (unsigned int i = 0 ; i < len ; i++) if (x[i].fd >= 0)
{
- if ((x[i].events & IOPAUSE_READ) && FD_ISSET(x[i].fd, &rfds))
+ if (x[i].events & IOPAUSE_READ && FD_ISSET(x[i].fd, &rfds))
x[i].revents |= IOPAUSE_READ ;
- if ((x[i].events & IOPAUSE_WRITE) && FD_ISSET(x[i].fd, &wfds))
+ if (x[i].events & IOPAUSE_WRITE && FD_ISSET(x[i].fd, &wfds))
x[i].revents |= IOPAUSE_WRITE ;
- if ((x[i].events & IOPAUSE_EXCEPT) && FD_ISSET(x[i].fd, &xfds))
- x[i].revents |= IOPAUSE_EXCEPT ;
+ if (x[i].events & IOPAUSE_EXCEPT && FD_ISSET(x[i].fd, &xfds))
+ x[i].revents |= x[i].events |= IOPAUSE_EXCEPT ;
}
- }
return r ;
}
diff --git a/src/libstddjb/ip4_netmask.c b/src/libstddjb/ip4_netmask.c
new file mode 100644
index 0000000..19f485f
--- /dev/null
+++ b/src/libstddjb/ip4_netmask.c
@@ -0,0 +1,14 @@
+/* ISC license. */
+
+#include <skalibs/uint32.h>
+#include <skalibs/fmtscan.h>
+
+int ip4_netmask (char *ip, uint8_t netmask)
+{
+ uint32_t u ;
+ if (netmask > 32) return 0 ;
+ uint32_unpack_big(ip, &u) ;
+ u &= netmask ? ~((1u << 32 - netmask) - 1) : 0 ;
+ uint32_pack_big(ip, u) ;
+ return 1 ;
+}
diff --git a/src/libstddjb/ip6_netmask.c b/src/libstddjb/ip6_netmask.c
new file mode 100644
index 0000000..5d8b13e
--- /dev/null
+++ b/src/libstddjb/ip6_netmask.c
@@ -0,0 +1,26 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/uint64.h>
+#include <skalibs/fmtscan.h>
+
+static void apply (char *half, uint8_t netmask)
+{
+ uint64_t u ;
+ uint64_unpack_big(half, &u) ;
+ u &= netmask ? ~((1ull << 64 - netmask) - 1) : 0 ;
+ uint64_pack_big(half, u) ;
+}
+
+int ip6_netmask (char *ip, uint8_t netmask)
+{
+ if (netmask > 128) return 0 ;
+ if (netmask <= 64)
+ {
+ apply(ip, netmask) ;
+ memset(ip + 8, 0, 8) ;
+ }
+ else apply(ip + 8, netmask - 64) ;
+ return 1 ;
+}
diff --git a/src/libunixonacid/unixmessage_bits_closeall.c b/src/libunixonacid/unixmessage_bits_closeall.c
index 54c79b2..15d4e5e 100644
--- a/src/libunixonacid/unixmessage_bits_closeall.c
+++ b/src/libunixonacid/unixmessage_bits_closeall.c
@@ -4,13 +4,9 @@
#include <skalibs/unixmessage.h>
static unsigned char const unixmessage_bits_closeall_[bitarray_div8(UNIXMESSAGE_MAXFDS)] =
-"\377"
-// "\377" "\377" // 253 = 255 & ~2
-"\377" "\377" "\377" "\377"
"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
-"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
-"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
-"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
-"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
+"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
+"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
+"\377" "\377" "\377" "\377" "\377" "\377" "\377" "\377"
;
unsigned char const *const unixmessage_bits_closeall = unixmessage_bits_closeall_ ;