summaryrefslogtreecommitdiff
path: root/src/libstddjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb')
-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
5 files changed, 67 insertions, 21 deletions
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 ;
+}