diff options
-rw-r--r-- | package/deps.mak | 2 | ||||
-rw-r--r-- | src/include/skalibs/fmtscan.h | 7 | ||||
-rw-r--r-- | src/libstddjb/iopause_poll.c | 8 | ||||
-rw-r--r-- | src/libstddjb/iopause_ppoll.c | 8 | ||||
-rw-r--r-- | src/libstddjb/iopause_select.c | 32 | ||||
-rw-r--r-- | src/libstddjb/ip4_netmask.c | 14 | ||||
-rw-r--r-- | src/libstddjb/ip6_netmask.c | 26 | ||||
-rw-r--r-- | src/libunixonacid/unixmessage_bits_closeall.c | 10 |
8 files changed, 78 insertions, 29 deletions
diff --git a/package/deps.mak b/package/deps.mak index e325d61..e88a469 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -395,11 +395,13 @@ src/libstddjb/ip46_scan.o src/libstddjb/ip46_scan.lo: src/libstddjb/ip46_scan.c src/libstddjb/ip46_scanlist.o src/libstddjb/ip46_scanlist.lo: src/libstddjb/ip46_scanlist.c src/include/skalibs/fmtscan.h src/include/skalibs/ip46.h src/libstddjb/ip4_fmt.o src/libstddjb/ip4_fmt.lo: src/libstddjb/ip4_fmt.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h src/libstddjb/ip4_fmtu32.o src/libstddjb/ip4_fmtu32.lo: src/libstddjb/ip4_fmtu32.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h +src/libstddjb/ip4_netmask.o src/libstddjb/ip4_netmask.lo: src/libstddjb/ip4_netmask.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h src/libstddjb/ip4_scan.o src/libstddjb/ip4_scan.lo: src/libstddjb/ip4_scan.c src/include/skalibs/fmtscan.h src/include/skalibs/types.h src/libstddjb/ip4_scanlist.o src/libstddjb/ip4_scanlist.lo: src/libstddjb/ip4_scanlist.c src/include/skalibs/fmtscan.h src/libstddjb/ip4_scanlist_u32.o src/libstddjb/ip4_scanlist_u32.lo: src/libstddjb/ip4_scanlist_u32.c src/include/skalibs/fmtscan.h src/libstddjb/ip4_scanu32.o src/libstddjb/ip4_scanu32.lo: src/libstddjb/ip4_scanu32.c src/include/skalibs/fmtscan.h src/include/skalibs/uint32.h src/libstddjb/ip6_fmt.o src/libstddjb/ip6_fmt.lo: src/libstddjb/ip6_fmt.c src/include/skalibs/diuint.h src/include/skalibs/fmtscan.h +src/libstddjb/ip6_netmask.o src/libstddjb/ip6_netmask.lo: src/libstddjb/ip6_netmask.c src/include/skalibs/fmtscan.h src/include/skalibs/uint64.h src/libstddjb/ip6_scan.o src/libstddjb/ip6_scan.lo: src/libstddjb/ip6_scan.c src/include/skalibs/fmtscan.h src/include/skalibs/uint16.h src/libstddjb/ip6_scanlist.o src/libstddjb/ip6_scanlist.lo: src/libstddjb/ip6_scanlist.c src/include/skalibs/fmtscan.h src/libstddjb/ipc_accept.o src/libstddjb/ipc_accept.lo: src/libstddjb/ipc_accept.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/fcntl.h src/include/skalibs/nonposix.h src/include/skalibs/socket.h src/include/skalibs/sysdeps.h 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_ ; |