From: Mark Wooding Date: Mon, 2 May 2016 12:28:24 +0000 (+0100) Subject: noip.c: Hack ioctl(2) as well. X-Git-Tag: 1.2.0~43 X-Git-Url: https://git.distorted.org.uk/~mdw/preload-hacks/commitdiff_plain/658c1774604911024016a572a119688031d69d77 noip.c: Hack ioctl(2) as well. It appears that Java's network machinery does lots of probing of network addresses with ioctl(2), and /some/ of these ioctls don't work well with Unix-domain sockets. If we see one of these, then make a temporary Internet socket and do the ioctl on that instead. This really is quite unpleasant, but it seems to work well enough to make Gradle work, for example. --- diff --git a/noip.c b/noip.c index 2a09c16..b9043f0 100644 --- a/noip.c +++ b/noip.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -125,7 +126,8 @@ static aclnode *connect_real, **connect_tail = &connect_real; _(recvfrom, ssize_t, (int, void *buf, size_t, int, \ struct sockaddr *from, socklen_t *fromlen)) \ _(sendmsg, ssize_t, (int, const struct msghdr *, int)) \ - _(recvmsg, ssize_t, (int, struct msghdr *, int)) + _(recvmsg, ssize_t, (int, struct msghdr *, int)) \ + _(ioctl, int, (int, unsigned long, ...)) /* Function pointers to set up. */ #define DECL(imp, ret, args) static ret (*real_##imp) args; @@ -1367,6 +1369,36 @@ int setsockopt(int sk, int lev, int opt, const void *p, socklen_t len) return (real_setsockopt(sk, lev, opt, p, len)); } +int ioctl(int fd, unsigned long op, ...) +{ + va_list ap; + void *arg; + int sk; + int rc; + + va_start(ap, op); + arg = va_arg(ap, void *); + + switch (op) { + case SIOCGIFADDR: + case SIOCGIFBRDADDR: + case SIOCGIFDSTADDR: + case SIOCGIFNETMASK: + PRESERVING_ERRNO({ + if (fixup_real_ip_socket(fd, AF_INET, &sk)) goto real; + }); + rc = real_ioctl(sk, op, arg); + PRESERVING_ERRNO({ close(sk); }); + break; + default: + real: + rc = real_ioctl(fd, op, arg); + break; + } + va_end(ap); + return (rc); +} + /*----- Initialization ----------------------------------------------------*/ /* Clean up the socket directory, deleting stale sockets. */