From 8f4a5e1c6fd669d57f06aaaaccd27fd19e4c9304 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Sun, 24 Apr 2011 17:40:25 +0000 Subject: [PATCH] Cleaned up socket() --- src/ipxwrapper.h | 12 +----------- src/winsock.c | 12 +++++------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/ipxwrapper.h b/src/ipxwrapper.h index 5b54262..a7f93df 100644 --- a/src/ipxwrapper.h +++ b/src/ipxwrapper.h @@ -40,16 +40,6 @@ #define IPX_SEND (int)(1<<3) #define IPX_RECV (int)(1<<4) -#define INIT_SOCKET(ptr) \ - (ptr)->fd = -1;\ - (ptr)->flags = IPX_SEND | IPX_RECV;\ - (ptr)->s_ptype = 0;\ - (ptr)->f_ptype = 0;\ - memset((ptr)->netnum, 0, 4);\ - memset((ptr)->nodenum, 0, 6);\ - (ptr)->socket = 0;\ - (ptr)->next = NULL; - #define RETURN(...) \ unlock_mutex();\ return __VA_ARGS__; @@ -94,7 +84,7 @@ struct ipx_socket { int flags; uint8_t s_ptype; - uint8_t f_ptype; + uint8_t f_ptype; /* Undefined when IPX_FILTER isn't set */ /* The following values are undefined when IPX_BOUND is not set */ unsigned char netnum[4]; diff --git a/src/winsock.c b/src/winsock.c index a27f711..9c04d2c 100644 --- a/src/winsock.c +++ b/src/winsock.c @@ -174,26 +174,24 @@ SOCKET WSAAPI socket(int af, int type, int protocol) { RETURN_WSA(ERROR_OUTOFMEMORY, -1); } - INIT_SOCKET(nsock); - nsock->fd = r_socket(AF_INET, SOCK_DGRAM, 0); if(nsock->fd == -1) { - debug("...failed: %s", w32_error(WSAGetLastError())); + debug("Creating fake socket failed: %s", w32_error(WSAGetLastError())); free(nsock); RETURN(-1); } - if(protocol) { - nsock->s_ptype = NSPROTO_IPX - protocol; - } + nsock->flags = IPX_SEND | IPX_RECV; + nsock->s_ptype = (protocol ? nsock->s_ptype = NSPROTO_IPX - protocol : 0); lock_mutex(); nsock->next = sockets; sockets = nsock; - debug("...success: fd=%d", nsock->fd); + debug("Socket created (fd=%d)", nsock->fd); + RETURN(nsock->fd); }else{ return r_socket(af, type, protocol);