mirror of
https://github.com/solemnwarning/ipxwrapper
synced 2024-12-30 16:45:37 +01:00
Cleaned up socket()
This commit is contained in:
parent
53346c2536
commit
8f4a5e1c6f
@ -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];
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user