1
0
mirror of https://github.com/solemnwarning/ipxwrapper synced 2024-12-30 16:45:37 +01:00

Implemented ioctlsocket() wrapper with support for FIONREAD.

This commit is contained in:
Daniel Collins 2010-01-09 16:20:18 +00:00
parent 4628d507bb
commit a3fba1773d
4 changed files with 35 additions and 0 deletions

View File

@ -13,3 +13,4 @@ EXPORTS
EnumProtocolsA
EnumProtocolsW
WSARecvEx
ioctlsocket

View File

@ -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 */

View File

@ -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

View File

@ -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));
}
}