From: Sven M. Hallberg Date: Fri, 29 Aug 2014 16:51:12 +0000 (+0200) Subject: add ioctl as a wrapper around ioctlsocket X-Git-Url: http://git.meshlink.io/?p=catta;a=commitdiff_plain;h=bce1f237f898509a4ea59fa29b290738be9b32a8 add ioctl as a wrapper around ioctlsocket --- diff --git a/src/compat/windows/wincompat.c b/src/compat/windows/wincompat.c index 1a05d9f..67cf853 100644 --- a/src/compat/windows/wincompat.c +++ b/src/compat/windows/wincompat.c @@ -190,6 +190,24 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) return bytessent; } +int ioctl(int d, unsigned long request, int *p) +{ + u_long arg = 0; + + if(ioctlsocket(d, request, &arg) == SOCKET_ERROR) { + errno = wsa_errno(); + return -1; + } + + if(arg > INT_MAX) { + errno = EINVAL; + return -1; + } + + *p = arg; + return 0; +} + int uname(struct utsname *buf) { SYSTEM_INFO si; diff --git a/src/compat/windows/wincompat.h b/src/compat/windows/wincompat.h index f76dbc4..b502022 100644 --- a/src/compat/windows/wincompat.h +++ b/src/compat/windows/wincompat.h @@ -77,6 +77,12 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); #endif +// Windows doesn't have ioctl but offers ioctlsocket for some socket-related +// functions. Unfortunately, argument types differ, so we implement a +// (restricted) wrapper. +int ioctl(int d, unsigned long request, int *p); + + // Windows logically doesn't have uname, so we supply a replacement. struct utsname {