diff --git a/src/ipxwrapper.def b/src/ipxwrapper.def index efb3726..d373277 100644 --- a/src/ipxwrapper.def +++ b/src/ipxwrapper.def @@ -13,3 +13,4 @@ EXPORTS EnumProtocolsA EnumProtocolsW WSARecvEx + ioctlsocket diff --git a/src/ipxwrapper.h b/src/ipxwrapper.h index 86e71f5..74704cd 100644 --- a/src/ipxwrapper.h +++ b/src/ipxwrapper.h @@ -169,5 +169,6 @@ int WSAAPI r_sendto(SOCKET,const char*,int,int,const struct sockaddr*,int); int WSAAPI r_setsockopt(SOCKET,int,int,const char*,int); int WSAAPI r_shutdown(SOCKET,int); SOCKET WSAAPI r_socket(int,int,int); +int PASCAL r_ioctlsocket(SOCKET fd, long cmd, u_long *argp); #endif /* !IPXWRAPPER_H */ diff --git a/src/ipxwrapper_stubs.txt b/src/ipxwrapper_stubs.txt index 77b8a4f..cab1044 100644 --- a/src/ipxwrapper_stubs.txt +++ b/src/ipxwrapper_stubs.txt @@ -7,6 +7,7 @@ htonl ntohl htons ntohs +select r_EnumProtocolsA r_EnumProtocolsW r_WSARecvEx @@ -20,3 +21,4 @@ r_sendto r_setsockopt r_shutdown r_socket +r_ioctlsocket diff --git a/src/winsock.c b/src/winsock.c index 506e41b..46571ac 100644 --- a/src/winsock.c +++ b/src/winsock.c @@ -658,3 +658,34 @@ int PASCAL shutdown(SOCKET fd, int cmd) { RETURN(r_shutdown(fd, cmd)); } } + +int PASCAL ioctlsocket(SOCKET fd, long cmd, u_long *argp) { + ipx_socket *sockptr = get_socket(fd); + + if(sockptr && cmd == FIONREAD) { + ipx_packet packet; + fd_set fdset; + struct timeval tv = {0,0}; + + FD_ZERO(&fdset); + FD_SET(sockptr->fd, &fdset); + + int r = select(1, &fdset, NULL, NULL, &tv); + if(r == -1) { + RETURN(-1); + }else if(r == 0) { + *(unsigned long*)argp = 0; + RETURN(0); + } + + r = r_recv(sockptr->fd, (char*)&packet, sizeof(packet), MSG_PEEK); + if(r == -1 && WSAGetLastError() != WSAEMSGSIZE) { + RETURN(-1); + } + + *(unsigned long*)argp = packet.size; + RETURN(0); + }else{ + RETURN(r_ioctlsocket(fd, cmd, argp)); + } +}