From b408f4e4e9da27d0e78fb0d5d0de43aa9d056209 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sun, 5 Jan 2014 21:46:59 +0000 Subject: [PATCH] Implemented listen function. --- src/ipxwrapper.def | 1 + src/ipxwrapper.h | 2 ++ src/ipxwrapper_stubs.txt | 2 +- src/winsock.c | 49 ++++++++++++++++++++++++++++++++++++++++ src/wsock32_stubs.txt | 2 +- 5 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/ipxwrapper.def b/src/ipxwrapper.def index 96db8d1..5881ed7 100644 --- a/src/ipxwrapper.def +++ b/src/ipxwrapper.def @@ -18,3 +18,4 @@ EXPORTS connect send getpeername + listen diff --git a/src/ipxwrapper.h b/src/ipxwrapper.h index 430ffbd..e49a231 100644 --- a/src/ipxwrapper.h +++ b/src/ipxwrapper.h @@ -43,6 +43,7 @@ #define IPX_EXT_ADDR (int)(1<<9) #define IPX_IS_SPX (int)(1<<10) #define IPX_IS_SPXII (int)(1<<11) +#define IPX_LISTENING (int)(1<<12) typedef struct ipx_socket ipx_socket; typedef struct ipx_packet ipx_packet; @@ -109,5 +110,6 @@ int PASCAL r_ioctlsocket(SOCKET fd, long cmd, u_long *argp); int PASCAL r_connect(SOCKET fd, const struct sockaddr *addr, int addrlen); int PASCAL r_send(SOCKET fd, const char *buf, int len, int flags); int PASCAL r_getpeername(SOCKET fd, struct sockaddr *addr, int *addrlen); +int PASCAL r_listen(SOCKET s, int backlog); #endif /* !IPXWRAPPER_H */ diff --git a/src/ipxwrapper_stubs.txt b/src/ipxwrapper_stubs.txt index 5bf1671..59ddfdb 100644 --- a/src/ipxwrapper_stubs.txt +++ b/src/ipxwrapper_stubs.txt @@ -8,7 +8,7 @@ ntohl:4 htons:4 ntohs:4 select:4 -listen:4 +r_listen:4 accept:4 send:4 connect:4 diff --git a/src/winsock.c b/src/winsock.c index cb9597b..83093ae 100644 --- a/src/winsock.c +++ b/src/winsock.c @@ -1307,3 +1307,52 @@ int PASCAL getpeername(SOCKET fd, struct sockaddr *addr, int *addrlen) return r_getpeername(fd, addr, addrlen); } } + +int PASCAL listen(SOCKET s, int backlog) +{ + ipx_socket *sock = get_socket(s); + + if(sock) + { + if(sock->flags & IPX_IS_SPX) + { + if(!(sock->flags & IPX_BOUND)) + { + unlock_sockets(); + + WSASetLastError(WSAEINVAL); + return -1; + } + + if(sock->flags & IPX_LISTENING) + { + unlock_sockets(); + + WSASetLastError(WSAEISCONN); + return -1; + } + + if(r_listen(sock->fd, backlog) == -1) + { + unlock_sockets(); + + return -1; + } + + sock->flags |= IPX_LISTENING; + + unlock_sockets(); + + return 0; + } + else{ + unlock_sockets(); + + WSASetLastError(WSAEOPNOTSUPP); + return -1; + } + } + else{ + return r_listen(s, backlog); + } +} diff --git a/src/wsock32_stubs.txt b/src/wsock32_stubs.txt index 59c54ec..aa67678 100644 --- a/src/wsock32_stubs.txt +++ b/src/wsock32_stubs.txt @@ -10,7 +10,7 @@ htons inet_addr inet_ntoa ioctlsocket:0 -listen +listen:0 ntohl ntohs recv:0