mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-13 23:40:58 +00:00
net_udp, net_wins, net_wipx network drivers update:
- do not try to set the quake hostname to the machine name if it isn't set. - use the newly added unix/windows socket api compatibility macros from net_sys.h: using just an int as the socketfd wasn't a problem without win64 support: the windows SOCKET type is not only unsigned but may actually be wider (uintptr_t, which is 8 bytes on win64). git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@220 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
b1835226d6
commit
6fa1c54ada
8 changed files with 282 additions and 277 deletions
|
@ -137,7 +137,7 @@ typedef struct qsocket_s
|
|||
|
||||
int driver;
|
||||
int landriver;
|
||||
int socket;
|
||||
sys_socket_t socket;
|
||||
void *driverdata;
|
||||
|
||||
unsigned int ackSequence;
|
||||
|
@ -164,22 +164,22 @@ typedef struct
|
|||
{
|
||||
char *name;
|
||||
qboolean initialized;
|
||||
int controlSock;
|
||||
int (*Init) (void);
|
||||
sys_socket_t controlSock;
|
||||
sys_socket_t (*Init) (void);
|
||||
void (*Shutdown) (void);
|
||||
void (*Listen) (qboolean state);
|
||||
int (*Open_Socket) (int port);
|
||||
int (*Close_Socket) (int socket);
|
||||
int (*Connect) (int socket, struct qsockaddr *addr);
|
||||
int (*CheckNewConnections) (void);
|
||||
int (*Read) (int socket, byte *buf, int len, struct qsockaddr *addr);
|
||||
int (*Write) (int socket, byte *buf, int len, struct qsockaddr *addr);
|
||||
int (*Broadcast) (int socket, byte *buf, int len);
|
||||
sys_socket_t (*Open_Socket) (int port);
|
||||
int (*Close_Socket) (sys_socket_t socketid);
|
||||
int (*Connect) (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
sys_socket_t (*CheckNewConnections) (void);
|
||||
int (*Read) (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int (*Write) (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int (*Broadcast) (sys_socket_t socketid, byte *buf, int len);
|
||||
char * (*AddrToString) (struct qsockaddr *addr);
|
||||
int (*StringToAddr) (char *string, struct qsockaddr *addr);
|
||||
int (*GetSocketAddr) (int socket, struct qsockaddr *addr);
|
||||
int (*GetNameFromAddr) (struct qsockaddr *addr, char *name);
|
||||
int (*GetAddrFromName) (char *name, struct qsockaddr *addr);
|
||||
int (*StringToAddr) (char *string, struct qsockaddr *addr);
|
||||
int (*GetSocketAddr) (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
int (*GetNameFromAddr) (struct qsockaddr *addr, char *name);
|
||||
int (*GetAddrFromName) (char *name, struct qsockaddr *addr);
|
||||
int (*AddrCompare) (struct qsockaddr *addr1, struct qsockaddr *addr2);
|
||||
int (*GetSocketPort) (struct qsockaddr *addr);
|
||||
int (*SetSocketPort) (struct qsockaddr *addr, int port);
|
||||
|
@ -197,7 +197,7 @@ typedef struct
|
|||
void (*Listen) (qboolean state);
|
||||
void (*SearchForHosts) (qboolean xmit);
|
||||
qsocket_t *(*Connect) (char *host);
|
||||
qsocket_t *(*CheckNewConnections) (void);
|
||||
qsocket_t *(*CheckNewConnections) (void);
|
||||
int (*QGetMessage) (qsocket_t *sock);
|
||||
int (*QSendMessage) (qsocket_t *sock, sizebuf_t *data);
|
||||
int (*SendUnreliableMessage) (qsocket_t *sock, sizebuf_t *data);
|
||||
|
|
|
@ -785,7 +785,8 @@ JustDoIt:
|
|||
|
||||
int Datagram_Init (void)
|
||||
{
|
||||
int i, csock, num_inited;
|
||||
int i, num_inited;
|
||||
sys_socket_t csock;
|
||||
|
||||
#ifdef BAN_TEST
|
||||
banAddr.s_addr = INADDR_ANY;
|
||||
|
@ -801,7 +802,7 @@ int Datagram_Init (void)
|
|||
for (i = 0; i < net_numlandrivers; i++)
|
||||
{
|
||||
csock = net_landrivers[i].Init ();
|
||||
if (csock == -1)
|
||||
if (csock == INVALID_SOCKET)
|
||||
continue;
|
||||
net_landrivers[i].initialized = true;
|
||||
net_landrivers[i].controlSock = csock;
|
||||
|
@ -861,8 +862,8 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
|
|||
{
|
||||
struct qsockaddr clientaddr;
|
||||
struct qsockaddr newaddr;
|
||||
int newsock;
|
||||
int acceptsock;
|
||||
sys_socket_t newsock;
|
||||
sys_socket_t acceptsock;
|
||||
qsocket_t *sock;
|
||||
qsocket_t *s;
|
||||
int len;
|
||||
|
@ -871,7 +872,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
|
|||
int ret;
|
||||
|
||||
acceptsock = dfunc.CheckNewConnections();
|
||||
if (acceptsock == -1)
|
||||
if (acceptsock == INVALID_SOCKET)
|
||||
return NULL;
|
||||
|
||||
SZ_Clear(&net_message);
|
||||
|
@ -1084,7 +1085,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
|
|||
|
||||
// allocate a network socket
|
||||
newsock = dfunc.Open_Socket(0);
|
||||
if (newsock == -1)
|
||||
if (newsock == INVALID_SOCKET)
|
||||
{
|
||||
NET_FreeQSocket(sock);
|
||||
return NULL;
|
||||
|
@ -1254,7 +1255,7 @@ static qsocket_t *_Datagram_Connect (char *host)
|
|||
struct qsockaddr sendaddr;
|
||||
struct qsockaddr readaddr;
|
||||
qsocket_t *sock;
|
||||
int newsock;
|
||||
sys_socket_t newsock;
|
||||
int ret;
|
||||
int reps;
|
||||
double start_time;
|
||||
|
@ -1269,7 +1270,7 @@ static qsocket_t *_Datagram_Connect (char *host)
|
|||
}
|
||||
|
||||
newsock = dfunc.Open_Socket (0);
|
||||
if (newsock == -1)
|
||||
if (newsock == INVALID_SOCKET)
|
||||
return NULL;
|
||||
|
||||
sock = NET_NewQSocket ();
|
||||
|
@ -1283,7 +1284,8 @@ static qsocket_t *_Datagram_Connect (char *host)
|
|||
goto ErrorReturn;
|
||||
|
||||
// send the connection request
|
||||
Con_Printf("trying...\n"); SCR_UpdateScreen ();
|
||||
Con_Printf("trying...\n");
|
||||
SCR_UpdateScreen ();
|
||||
start_time = net_time;
|
||||
|
||||
for (reps = 0; reps < 3; reps++)
|
||||
|
|
152
Quake/net_udp.c
152
Quake/net_udp.c
|
@ -25,9 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "quakedef.h"
|
||||
#include "net_defs.h"
|
||||
|
||||
static int net_acceptsocket = -1; // socket for fielding new connections
|
||||
static int net_controlsocket;
|
||||
static int net_broadcastsocket = 0;
|
||||
static sys_socket_t net_acceptsocket = INVALID_SOCKET; // socket for fielding new connections
|
||||
static sys_socket_t net_controlsocket;
|
||||
static sys_socket_t net_broadcastsocket = 0;
|
||||
static struct sockaddr_in broadcastaddr;
|
||||
|
||||
static in_addr_t myAddr;
|
||||
|
@ -36,58 +36,53 @@ static in_addr_t myAddr;
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_Init (void)
|
||||
sys_socket_t UDP_Init (void)
|
||||
{
|
||||
struct hostent *local;
|
||||
char *colon;
|
||||
char buff[MAXHOSTNAMELEN];
|
||||
struct qsockaddr addr;
|
||||
char *colon;
|
||||
|
||||
struct hostent *local;
|
||||
struct qsockaddr addr;
|
||||
|
||||
if (COM_CheckParm ("-noudp"))
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
|
||||
// determine my name & address
|
||||
myAddr = htonl(INADDR_LOOPBACK);
|
||||
if (gethostname(buff, MAXHOSTNAMELEN) != 0)
|
||||
{
|
||||
Con_Printf ("UDP init failed. Disabling UDP...\n");
|
||||
return -1;
|
||||
Con_SafePrintf("UDP_Init: WARNING: gethostname failed\n");
|
||||
}
|
||||
|
||||
local = gethostbyname(buff);
|
||||
if (local == NULL)
|
||||
else
|
||||
{
|
||||
Con_Printf ("UDP init failed. Disabling UDP...\n");
|
||||
return -1;
|
||||
buff[MAXHOSTNAMELEN - 1] = 0;
|
||||
local = gethostbyname(buff);
|
||||
if (local == NULL)
|
||||
{
|
||||
Con_SafePrintf("UDP_Init: WARNING: gethostbyname failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
myAddr = *(in_addr_t *)local->h_addr_list[0];
|
||||
}
|
||||
}
|
||||
|
||||
myAddr = *(in_addr_t *)local->h_addr_list[0];
|
||||
|
||||
// if the quake hostname isn't set, set it to the machine name
|
||||
if (Q_strcmp(hostname.string, "UNNAMED") == 0)
|
||||
if ((net_controlsocket = UDP_OpenSocket(0)) == INVALID_SOCKET)
|
||||
{
|
||||
buff[15] = 0;
|
||||
Cvar_Set ("hostname", buff);
|
||||
Con_SafePrintf("%s: Unable to open control socket, UDP disabled\n");
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if ((net_controlsocket = UDP_OpenSocket (0)) == -1)
|
||||
Sys_Error("UDP_Init: Unable to open control socket\n");
|
||||
|
||||
broadcastaddr.sin_family = AF_INET;
|
||||
broadcastaddr.sin_addr.s_addr = INADDR_BROADCAST;
|
||||
broadcastaddr.sin_port = htons((unsigned short)net_hostport);
|
||||
|
||||
if (UDP_GetSocketAddr (net_controlsocket, &addr) != 0)
|
||||
{
|
||||
Con_Printf ("UDP init failed. Disabling UDP...\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Q_strcpy(my_tcpip_address, UDP_AddrToString (&addr));
|
||||
UDP_GetSocketAddr (net_controlsocket, &addr);
|
||||
Q_strcpy(my_tcpip_address, UDP_AddrToString (&addr));
|
||||
colon = Q_strrchr (my_tcpip_address, ':');
|
||||
if (colon)
|
||||
*colon = 0;
|
||||
|
||||
Con_Printf("UDP Initialized\n");
|
||||
Con_SafePrintf("UDP Initialized\n");
|
||||
tcpipAvailable = true;
|
||||
|
||||
return net_controlsocket;
|
||||
|
@ -108,58 +103,57 @@ void UDP_Listen (qboolean state)
|
|||
// enable listening
|
||||
if (state)
|
||||
{
|
||||
if (net_acceptsocket != -1)
|
||||
if (net_acceptsocket != INVALID_SOCKET)
|
||||
return;
|
||||
if ((net_acceptsocket = UDP_OpenSocket (net_hostport)) == -1)
|
||||
Sys_Error ("UDP_Listen: Unable to open accept socket\n");
|
||||
if ((net_acceptsocket = UDP_OpenSocket (net_hostport)) == INVALID_SOCKET)
|
||||
Sys_Error ("UDP_Listen: Unable to open accept socket");
|
||||
return;
|
||||
}
|
||||
|
||||
// disable listening
|
||||
if (net_acceptsocket == -1)
|
||||
if (net_acceptsocket == INVALID_SOCKET)
|
||||
return;
|
||||
UDP_CloseSocket (net_acceptsocket);
|
||||
net_acceptsocket = -1;
|
||||
net_acceptsocket = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_OpenSocket (int port)
|
||||
sys_socket_t UDP_OpenSocket (int port)
|
||||
{
|
||||
int newsocket;
|
||||
sys_socket_t newsocket;
|
||||
struct sockaddr_in address;
|
||||
int _true = 1;
|
||||
|
||||
if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
|
||||
return -1;
|
||||
if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
|
||||
return INVALID_SOCKET;
|
||||
|
||||
if (ioctl (newsocket, FIONBIO, (char *)&_true) == -1)
|
||||
if (ioctlsocket (newsocket, FIONBIO, &_true) == SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
|
||||
memset(&address, 0, sizeof(struct sockaddr_in));
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
address.sin_port = htons(port);
|
||||
if( bind (newsocket, (void *)&address, sizeof(address)) == -1)
|
||||
goto ErrorReturn;
|
||||
|
||||
return newsocket;
|
||||
address.sin_port = htons((unsigned short)port);
|
||||
if (bind (newsocket, (struct sockaddr *)&address, sizeof(address)) == 0)
|
||||
return newsocket;
|
||||
|
||||
ErrorReturn:
|
||||
close (newsocket);
|
||||
return -1;
|
||||
UDP_CloseSocket (newsocket);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_CloseSocket (int socketid)
|
||||
int UDP_CloseSocket (sys_socket_t socketid)
|
||||
{
|
||||
if (socketid == net_broadcastsocket)
|
||||
net_broadcastsocket = 0;
|
||||
return close (socketid);
|
||||
return closesocket (socketid);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
||||
/*
|
||||
============
|
||||
PartialIPAddress
|
||||
|
@ -215,30 +209,32 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr)
|
|||
}
|
||||
//=============================================================================
|
||||
|
||||
int UDP_Connect (int socketid, struct qsockaddr *addr)
|
||||
int UDP_Connect (sys_socket_t socketid, struct qsockaddr *addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_CheckNewConnections (void)
|
||||
sys_socket_t UDP_CheckNewConnections (void)
|
||||
{
|
||||
unsigned long available;
|
||||
struct sockaddr_in from;
|
||||
socklen_t fromlen;
|
||||
char buff[1];
|
||||
|
||||
if (net_acceptsocket == -1)
|
||||
return -1;
|
||||
if (net_acceptsocket == INVALID_SOCKET)
|
||||
return INVALID_SOCKET;
|
||||
|
||||
if (ioctl (net_acceptsocket, FIONREAD, &available) == -1)
|
||||
Sys_Error ("UDP: ioctlsocket (FIONREAD) failed\n");
|
||||
{
|
||||
Sys_Error ("UDP: ioctlsocket (FIONREAD) failed");
|
||||
}
|
||||
if (available)
|
||||
return net_acceptsocket;
|
||||
// quietly absorb empty packets
|
||||
recvfrom (net_acceptsocket, buff, 0, 0, (struct sockaddr *) &from, &fromlen);
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
@ -249,15 +245,19 @@ static void get_qsockaddr(struct sockaddr *saddr, struct qsockaddr *qaddr)
|
|||
memcpy(&(qaddr->qsa_data), &(saddr->sa_data), sizeof(qaddr->qsa_data));
|
||||
}
|
||||
|
||||
int UDP_Read (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
int UDP_Read (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
static struct sockaddr saddr;
|
||||
socklen_t addrlen = sizeof(struct sockaddr);
|
||||
int ret;
|
||||
|
||||
ret = recvfrom (socketid, buf, len, 0, &saddr, &addrlen);
|
||||
if (ret == -1 && (errno == EWOULDBLOCK || errno == ECONNREFUSED))
|
||||
return 0;
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
int err = SOCKETERRNO;
|
||||
if (err == EWOULDBLOCK || err == ECONNREFUSED)
|
||||
return 0;
|
||||
}
|
||||
|
||||
get_qsockaddr(&saddr, addr);
|
||||
return ret;
|
||||
|
@ -265,13 +265,16 @@ int UDP_Read (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_MakeSocketBroadcastCapable (int socketid)
|
||||
static int UDP_MakeSocketBroadcastCapable (sys_socket_t socketid)
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
// make this socket broadcast capable
|
||||
if (setsockopt(socketid, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) < 0)
|
||||
if (setsockopt(socketid, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i))
|
||||
== SOCKET_ERROR)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
net_broadcastsocket = socketid;
|
||||
|
||||
return 0;
|
||||
|
@ -279,7 +282,7 @@ int UDP_MakeSocketBroadcastCapable (int socketid)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_Broadcast (int socketid, byte *buf, int len)
|
||||
int UDP_Broadcast (sys_socket_t socketid, byte *buf, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -300,13 +303,18 @@ int UDP_Broadcast (int socketid, byte *buf, int len)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_Write (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
int UDP_Write (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sendto (socketid, buf, len, 0, (struct sockaddr *)addr, sizeof(struct qsockaddr));
|
||||
if (ret == -1 && errno == EWOULDBLOCK)
|
||||
return 0;
|
||||
ret = sendto (socketid, buf, len, 0, (struct sockaddr *)addr,
|
||||
sizeof(struct qsockaddr));
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
int err = SOCKETERRNO;
|
||||
if (err == EWOULDBLOCK)
|
||||
return 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -341,12 +349,12 @@ int UDP_StringToAddr (char *string, struct qsockaddr *addr)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int UDP_GetSocketAddr (int socketid, struct qsockaddr *addr)
|
||||
int UDP_GetSocketAddr (sys_socket_t socketid, struct qsockaddr *addr)
|
||||
{
|
||||
socklen_t addrlen = sizeof(struct qsockaddr);
|
||||
unsigned int a;
|
||||
in_addr_t a;
|
||||
|
||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||
memset(addr, 0, sizeof(struct qsockaddr));
|
||||
if (getsockname(socketid, (struct sockaddr *)addr, &addrlen) != 0)
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -23,19 +23,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
// net_udp.h
|
||||
|
||||
int UDP_Init (void);
|
||||
sys_socket_t UDP_Init (void);
|
||||
void UDP_Shutdown (void);
|
||||
void UDP_Listen (qboolean state);
|
||||
int UDP_OpenSocket (int port);
|
||||
int UDP_CloseSocket (int socketid);
|
||||
int UDP_Connect (int socketid, struct qsockaddr *addr);
|
||||
int UDP_CheckNewConnections (void);
|
||||
int UDP_Read (int socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int UDP_Write (int socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int UDP_Broadcast (int socketid, byte *buf, int len);
|
||||
sys_socket_t UDP_OpenSocket (int port);
|
||||
int UDP_CloseSocket (sys_socket_t socketid);
|
||||
int UDP_Connect (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
sys_socket_t UDP_CheckNewConnections (void);
|
||||
int UDP_Read (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int UDP_Write (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int UDP_Broadcast (sys_socket_t socketid, byte *buf, int len);
|
||||
char *UDP_AddrToString (struct qsockaddr *addr);
|
||||
int UDP_StringToAddr (char *string, struct qsockaddr *addr);
|
||||
int UDP_GetSocketAddr (int socketid, struct qsockaddr *addr);
|
||||
int UDP_GetSocketAddr (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name);
|
||||
int UDP_GetAddrFromName (char *name, struct qsockaddr *addr);
|
||||
int UDP_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2);
|
||||
|
|
134
Quake/net_wins.c
134
Quake/net_wins.c
|
@ -26,12 +26,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "quakedef.h"
|
||||
#include "net_defs.h"
|
||||
|
||||
static int net_acceptsocket = -1; // socket for fielding new connections
|
||||
static int net_controlsocket;
|
||||
static int net_broadcastsocket = 0;
|
||||
static sys_socket_t net_acceptsocket = INVALID_SOCKET; // socket for fielding new connections
|
||||
static sys_socket_t net_controlsocket;
|
||||
static sys_socket_t net_broadcastsocket = 0;
|
||||
static struct sockaddr_in broadcastaddr;
|
||||
|
||||
static u_long myAddr;
|
||||
static in_addr_t myAddr;
|
||||
|
||||
#include "net_wins.h"
|
||||
|
||||
|
@ -72,7 +72,7 @@ static void WINS_GetLocalAddress (void)
|
|||
{
|
||||
struct hostent *local = NULL;
|
||||
char buff[MAXHOSTNAMELEN];
|
||||
u_long addr;
|
||||
in_addr_t addr;
|
||||
|
||||
if (myAddr != INADDR_ANY)
|
||||
return;
|
||||
|
@ -87,18 +87,17 @@ static void WINS_GetLocalAddress (void)
|
|||
if (local == NULL)
|
||||
return;
|
||||
|
||||
myAddr = *(u_long *)local->h_addr_list[0];
|
||||
myAddr = *(in_addr_t *)local->h_addr_list[0];
|
||||
|
||||
addr = ntohl(myAddr);
|
||||
sprintf(my_tcpip_address, "%ld.%ld.%ld.%ld", (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
|
||||
}
|
||||
|
||||
|
||||
int WINS_Init (void)
|
||||
sys_socket_t WINS_Init (void)
|
||||
{
|
||||
int i, err;
|
||||
char buff[MAXHOSTNAMELEN];
|
||||
char *p;
|
||||
|
||||
if (COM_CheckParm ("-noudp"))
|
||||
return -1;
|
||||
|
@ -114,34 +113,15 @@ int WINS_Init (void)
|
|||
}
|
||||
winsock_initialized++;
|
||||
|
||||
// determine my name
|
||||
if (gethostname(buff, MAXHOSTNAMELEN) == SOCKET_ERROR)
|
||||
// determine my name & address
|
||||
if (gethostname(buff, MAXHOSTNAMELEN) != 0)
|
||||
{
|
||||
Con_DPrintf ("Winsock TCP/IP Initialization failed.\n");
|
||||
if (--winsock_initialized == 0)
|
||||
WSACleanup ();
|
||||
return -1;
|
||||
Con_SafePrintf("WINS_Init: WARNING: gethostname failed\n");
|
||||
}
|
||||
|
||||
// if the quake hostname isn't set, set it to the machine name
|
||||
if (Q_strcmp(hostname.string, "UNNAMED") == 0)
|
||||
else
|
||||
{
|
||||
// see if it's a text IP address (well, close enough)
|
||||
for (p = buff; *p; p++)
|
||||
if ((*p < '0' || *p > '9') && *p != '.')
|
||||
break;
|
||||
|
||||
// if it is a real name, strip off the domain; we only want the host
|
||||
if (*p)
|
||||
{
|
||||
for (i = 0; i < 15; i++)
|
||||
if (buff[i] == '.')
|
||||
break;
|
||||
buff[i] = 0;
|
||||
}
|
||||
Cvar_Set ("hostname", buff);
|
||||
buff[MAXHOSTNAMELEN - 1] = 0;
|
||||
}
|
||||
|
||||
i = COM_CheckParm ("-ip");
|
||||
if (i)
|
||||
{
|
||||
|
@ -163,19 +143,19 @@ int WINS_Init (void)
|
|||
strcpy(my_tcpip_address, "INADDR_ANY");
|
||||
}
|
||||
|
||||
if ((net_controlsocket = WINS_OpenSocket(0)) == -1)
|
||||
if ((net_controlsocket = WINS_OpenSocket(0)) == INVALID_SOCKET)
|
||||
{
|
||||
Con_Printf("WINS_Init: Unable to open control socket\n");
|
||||
Con_SafePrintf("WINS_Init: Unable to open control socket, UDP disabled\n");
|
||||
if (--winsock_initialized == 0)
|
||||
WSACleanup ();
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
broadcastaddr.sin_family = AF_INET;
|
||||
broadcastaddr.sin_addr.s_addr = INADDR_BROADCAST;
|
||||
broadcastaddr.sin_port = htons((unsigned short)net_hostport);
|
||||
|
||||
Con_Printf("Winsock TCP/IP Initialized\n");
|
||||
Con_SafePrintf("UDP Initialized\n");
|
||||
tcpipAvailable = true;
|
||||
|
||||
return net_controlsocket;
|
||||
|
@ -198,58 +178,64 @@ void WINS_Listen (qboolean state)
|
|||
// enable listening
|
||||
if (state)
|
||||
{
|
||||
if (net_acceptsocket != -1)
|
||||
if (net_acceptsocket != INVALID_SOCKET)
|
||||
return;
|
||||
WINS_GetLocalAddress();
|
||||
if ((net_acceptsocket = WINS_OpenSocket (net_hostport)) == -1)
|
||||
Sys_Error ("WINS_Listen: Unable to open accept socket\n");
|
||||
if ((net_acceptsocket = WINS_OpenSocket (net_hostport)) == INVALID_SOCKET)
|
||||
Sys_Error ("WINS_Listen: Unable to open accept socket");
|
||||
return;
|
||||
}
|
||||
|
||||
// disable listening
|
||||
if (net_acceptsocket == -1)
|
||||
if (net_acceptsocket == INVALID_SOCKET)
|
||||
return;
|
||||
WINS_CloseSocket (net_acceptsocket);
|
||||
net_acceptsocket = -1;
|
||||
net_acceptsocket = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_OpenSocket (int port)
|
||||
sys_socket_t WINS_OpenSocket (int port)
|
||||
{
|
||||
int newsocket;
|
||||
sys_socket_t newsocket;
|
||||
struct sockaddr_in address;
|
||||
u_long _true = 1;
|
||||
|
||||
if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
|
||||
return -1;
|
||||
if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
|
||||
return INVALID_SOCKET;
|
||||
|
||||
if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
|
||||
if (ioctlsocket (newsocket, FIONBIO, &_true) == SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
|
||||
memset(&address, 0, sizeof(struct sockaddr_in));
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr.s_addr = myAddr;
|
||||
address.sin_port = htons((unsigned short)port);
|
||||
if( bind (newsocket, (void *)&address, sizeof(address)) == 0)
|
||||
if (bind (newsocket, (struct sockaddr *)&address, sizeof(address)) == 0)
|
||||
return newsocket;
|
||||
|
||||
Sys_Error ("Unable to bind to %s", WINS_AddrToString((struct qsockaddr *)&address));
|
||||
if (tcpipAvailable)
|
||||
{
|
||||
Sys_Error ("Unable to bind to %s", WINS_AddrToString((struct qsockaddr *)&address));
|
||||
}
|
||||
/* else: we are still in init phase, no need to error */
|
||||
|
||||
ErrorReturn:
|
||||
closesocket (newsocket);
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_CloseSocket (int socketid)
|
||||
int WINS_CloseSocket (sys_socket_t socketid)
|
||||
{
|
||||
if (socketid == net_broadcastsocket)
|
||||
net_broadcastsocket = 0;
|
||||
return closesocket (socketid);
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
||||
/*
|
||||
============
|
||||
PartialIPAddress
|
||||
|
@ -306,56 +292,57 @@ static int PartialIPAddress (char *in, struct qsockaddr *hostaddr)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_Connect (int socketid, struct qsockaddr *addr)
|
||||
int WINS_Connect (sys_socket_t socketid, struct qsockaddr *addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_CheckNewConnections (void)
|
||||
sys_socket_t WINS_CheckNewConnections (void)
|
||||
{
|
||||
char buf[4096];
|
||||
|
||||
if (net_acceptsocket == -1)
|
||||
return -1;
|
||||
if (net_acceptsocket == INVALID_SOCKET)
|
||||
return INVALID_SOCKET;
|
||||
|
||||
if (recvfrom (net_acceptsocket, buf, sizeof(buf), MSG_PEEK, NULL, NULL)
|
||||
!= SOCKET_ERROR) /* >= 0 */
|
||||
{
|
||||
return net_acceptsocket;
|
||||
}
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_Read (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
int WINS_Read (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int addrlen = sizeof(struct qsockaddr);
|
||||
socklen_t addrlen = sizeof(struct qsockaddr);
|
||||
int ret;
|
||||
|
||||
ret = recvfrom (socketid, (char *)buf, len, 0, (struct sockaddr *)addr, &addrlen);
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK || err == WSAECONNREFUSED)
|
||||
int err = SOCKETERRNO;
|
||||
if (err == EWOULDBLOCK || err == ECONNREFUSED)
|
||||
return 0;
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_MakeSocketBroadcastCapable (int socketid)
|
||||
static int WINS_MakeSocketBroadcastCapable (sys_socket_t socketid)
|
||||
{
|
||||
int i = 1;
|
||||
|
||||
// make this socket broadcast capable
|
||||
if (setsockopt(socketid, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i))
|
||||
== SOCKET_ERROR)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
net_broadcastsocket = socketid;
|
||||
|
||||
return 0;
|
||||
|
@ -363,7 +350,7 @@ int WINS_MakeSocketBroadcastCapable (int socketid)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_Broadcast (int socketid, byte *buf, int len)
|
||||
int WINS_Broadcast (sys_socket_t socketid, byte *buf, int len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -385,7 +372,7 @@ int WINS_Broadcast (int socketid, byte *buf, int len)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_Write (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
int WINS_Write (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -393,10 +380,10 @@ int WINS_Write (int socketid, byte *buf, int len, struct qsockaddr *addr)
|
|||
sizeof(struct qsockaddr));
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
if (WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
int err = SOCKETERRNO;
|
||||
if (err == EWOULDBLOCK)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -431,15 +418,16 @@ int WINS_StringToAddr (char *string, struct qsockaddr *addr)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_GetSocketAddr (int socketid, struct qsockaddr *addr)
|
||||
int WINS_GetSocketAddr (sys_socket_t socketid, struct qsockaddr *addr)
|
||||
{
|
||||
int addrlen = sizeof(struct qsockaddr);
|
||||
unsigned int a;
|
||||
socklen_t addrlen = sizeof(struct qsockaddr);
|
||||
in_addr_t a;
|
||||
|
||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||
memset(addr, 0, sizeof(struct qsockaddr));
|
||||
getsockname(socketid, (struct sockaddr *)addr, &addrlen);
|
||||
|
||||
a = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
|
||||
if (a == 0 || a == inet_addr("127.0.0.1"))
|
||||
if (a == 0 || a == htonl(INADDR_LOOPBACK))
|
||||
((struct sockaddr_in *)addr)->sin_addr.s_addr = myAddr;
|
||||
|
||||
return 0;
|
||||
|
@ -465,7 +453,7 @@ int WINS_GetNameFromAddr (struct qsockaddr *addr, char *name)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int WINS_GetAddrFromName(char *name, struct qsockaddr *addr)
|
||||
int WINS_GetAddrFromName (char *name, struct qsockaddr *addr)
|
||||
{
|
||||
struct hostent *hostentry;
|
||||
|
||||
|
@ -479,7 +467,7 @@ int WINS_GetAddrFromName(char *name, struct qsockaddr *addr)
|
|||
addr->qsa_family = AF_INET;
|
||||
((struct sockaddr_in *)addr)->sin_port = htons((unsigned short)net_hostport);
|
||||
((struct sockaddr_in *)addr)->sin_addr.s_addr =
|
||||
*(u_long *)hostentry->h_addr_list[0];
|
||||
*(in_addr_t *)hostentry->h_addr_list[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,19 +24,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
// net_wins.h
|
||||
|
||||
int WINS_Init (void);
|
||||
sys_socket_t WINS_Init (void);
|
||||
void WINS_Shutdown (void);
|
||||
void WINS_Listen (qboolean state);
|
||||
int WINS_OpenSocket (int port);
|
||||
int WINS_CloseSocket (int socketid);
|
||||
int WINS_Connect (int socketid, struct qsockaddr *addr);
|
||||
int WINS_CheckNewConnections (void);
|
||||
int WINS_Read (int socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WINS_Write (int socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WINS_Broadcast (int socketid, byte *buf, int len);
|
||||
sys_socket_t WINS_OpenSocket (int port);
|
||||
int WINS_CloseSocket (sys_socket_t socketid);
|
||||
int WINS_Connect (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
sys_socket_t WINS_CheckNewConnections (void);
|
||||
int WINS_Read (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WINS_Write (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WINS_Broadcast (sys_socket_t socketid, byte *buf, int len);
|
||||
char *WINS_AddrToString (struct qsockaddr *addr);
|
||||
int WINS_StringToAddr (char *string, struct qsockaddr *addr);
|
||||
int WINS_GetSocketAddr (int socketid, struct qsockaddr *addr);
|
||||
int WINS_GetSocketAddr (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
int WINS_GetNameFromAddr (struct qsockaddr *addr, char *name);
|
||||
int WINS_GetAddrFromName (char *name, struct qsockaddr *addr);
|
||||
int WINS_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2);
|
||||
|
|
168
Quake/net_wipx.c
168
Quake/net_wipx.c
|
@ -30,36 +30,37 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
extern cvar_t hostname;
|
||||
|
||||
static int net_acceptsocket = -1; // socket for fielding new connections
|
||||
static int net_controlsocket;
|
||||
static sys_socket_t net_acceptsocket = INVALID_SOCKET; // socket for fielding new connections
|
||||
static sys_socket_t net_controlsocket;
|
||||
static struct sockaddr_ipx broadcastaddr;
|
||||
|
||||
/* externs from net_wins.c: */
|
||||
extern qboolean winsock_initialized;
|
||||
extern WSADATA winsockdata;
|
||||
|
||||
#define IPXSOCKETS 18
|
||||
static int ipxsocket[IPXSOCKETS];
|
||||
static sys_socket_t ipxsocket[IPXSOCKETS];
|
||||
static int sequence[IPXSOCKETS];
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_Init (void)
|
||||
sys_socket_t WIPX_Init (void)
|
||||
{
|
||||
int i, err;
|
||||
char *colon;
|
||||
char buff[MAXHOSTNAMELEN];
|
||||
struct qsockaddr addr;
|
||||
char *p;
|
||||
|
||||
if (COM_CheckParm ("-noipx"))
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
|
||||
if (winsock_initialized == 0)
|
||||
{
|
||||
err = WSAStartup(MAKEWORD(1,1), &winsockdata);
|
||||
if (err != 0)
|
||||
{
|
||||
Con_Printf ("Winsock initialization failed.\n");
|
||||
return -1;
|
||||
Con_SafePrintf("Winsock initialization failed.\n");
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
winsock_initialized++;
|
||||
|
@ -68,34 +69,21 @@ int WIPX_Init (void)
|
|||
ipxsocket[i] = 0;
|
||||
|
||||
// determine my name & address
|
||||
if (gethostname(buff, MAXHOSTNAMELEN) == 0)
|
||||
if (gethostname(buff, MAXHOSTNAMELEN) != 0)
|
||||
{
|
||||
// if the quake hostname isn't set, set it to the machine name
|
||||
if (Q_strcmp(hostname.string, "UNNAMED") == 0)
|
||||
{
|
||||
// see if it's a text IP address (well, close enough)
|
||||
for (p = buff; *p; p++)
|
||||
if ((*p < '0' || *p > '9') && *p != '.')
|
||||
break;
|
||||
|
||||
// if it is a real name, strip off the domain; we only want the host
|
||||
if (*p)
|
||||
{
|
||||
for (i = 0; i < 15; i++)
|
||||
if (buff[i] == '.')
|
||||
break;
|
||||
buff[i] = 0;
|
||||
}
|
||||
Cvar_Set ("hostname", buff);
|
||||
}
|
||||
Con_SafePrintf("WIPX_Init: WARNING: gethostname failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
buff[MAXHOSTNAMELEN - 1] = 0;
|
||||
}
|
||||
|
||||
if ((net_controlsocket = WIPX_OpenSocket(0)) == -1)
|
||||
if ((net_controlsocket = WIPX_OpenSocket(0)) == INVALID_SOCKET)
|
||||
{
|
||||
Con_Printf("WIPX_Init: Unable to open control socket\n");
|
||||
Con_SafePrintf("WIPX_Init: Unable to open control socket, IPX disabled\n");
|
||||
if (--winsock_initialized == 0)
|
||||
WSACleanup ();
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
broadcastaddr.sa_family = AF_IPX;
|
||||
|
@ -104,12 +92,12 @@ int WIPX_Init (void)
|
|||
broadcastaddr.sa_socket = htons((unsigned short)net_hostport);
|
||||
|
||||
WIPX_GetSocketAddr (net_controlsocket, &addr);
|
||||
Q_strcpy(my_ipx_address, WIPX_AddrToString (&addr));
|
||||
p = Q_strrchr (my_ipx_address, ':');
|
||||
if (p)
|
||||
*p = 0;
|
||||
Q_strcpy(my_ipx_address, WIPX_AddrToString (&addr));
|
||||
colon = Q_strrchr (my_ipx_address, ':');
|
||||
if (colon)
|
||||
*colon = 0;
|
||||
|
||||
Con_Printf("Winsock IPX Initialized\n");
|
||||
Con_SafePrintf("IPX Initialized\n");
|
||||
ipxAvailable = true;
|
||||
|
||||
return net_controlsocket;
|
||||
|
@ -132,39 +120,44 @@ void WIPX_Listen (qboolean state)
|
|||
// enable listening
|
||||
if (state)
|
||||
{
|
||||
if (net_acceptsocket != -1)
|
||||
if (net_acceptsocket != INVALID_SOCKET)
|
||||
return;
|
||||
if ((net_acceptsocket = WIPX_OpenSocket (net_hostport)) == -1)
|
||||
Sys_Error ("WIPX_Listen: Unable to open accept socket\n");
|
||||
if ((net_acceptsocket = WIPX_OpenSocket (net_hostport)) == INVALID_SOCKET)
|
||||
Sys_Error ("WIPX_Listen: Unable to open accept socket");
|
||||
return;
|
||||
}
|
||||
|
||||
// disable listening
|
||||
if (net_acceptsocket == -1)
|
||||
if (net_acceptsocket == INVALID_SOCKET)
|
||||
return;
|
||||
WIPX_CloseSocket (net_acceptsocket);
|
||||
net_acceptsocket = -1;
|
||||
net_acceptsocket = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_OpenSocket (int port)
|
||||
sys_socket_t WIPX_OpenSocket (int port)
|
||||
{
|
||||
int handle;
|
||||
int newsocket;
|
||||
sys_socket_t handle, newsocket;
|
||||
struct sockaddr_ipx address;
|
||||
u_long _true = 1;
|
||||
|
||||
for (handle = 0; handle < IPXSOCKETS; handle++)
|
||||
{
|
||||
if (ipxsocket[handle] == 0)
|
||||
break;
|
||||
}
|
||||
if (handle == IPXSOCKETS)
|
||||
return -1;
|
||||
{
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if ((newsocket = socket (AF_IPX, SOCK_DGRAM, NSPROTO_IPX)) == INVALID_SOCKET)
|
||||
return -1;
|
||||
{
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (ioctlsocket (newsocket, FIONBIO, &_true) == -1)
|
||||
if (ioctlsocket (newsocket, FIONBIO, &_true) == SOCKET_ERROR)
|
||||
goto ErrorReturn;
|
||||
|
||||
if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&_true, sizeof(_true))
|
||||
|
@ -175,24 +168,30 @@ int WIPX_OpenSocket (int port)
|
|||
memset(address.sa_netnum, 0, 4);
|
||||
memset(address.sa_nodenum, 0, 6);;
|
||||
address.sa_socket = htons((unsigned short)port);
|
||||
if( bind (newsocket, (void *)&address, sizeof(address)) == 0)
|
||||
if (bind (newsocket, (struct sockaddr *)&address, sizeof(address)) == 0)
|
||||
{
|
||||
ipxsocket[handle] = newsocket;
|
||||
sequence[handle] = 0;
|
||||
return handle;
|
||||
}
|
||||
|
||||
Sys_Error ("Winsock IPX bind failed\n");
|
||||
if (ipxAvailable)
|
||||
{
|
||||
Sys_Error ("IPX bind failed");
|
||||
return INVALID_SOCKET; /* not reached */
|
||||
}
|
||||
/* else: we are still in init phase, no need to error */
|
||||
|
||||
ErrorReturn:
|
||||
closesocket (newsocket);
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_CloseSocket (int handle)
|
||||
int WIPX_CloseSocket (sys_socket_t handle)
|
||||
{
|
||||
int socketid = ipxsocket[handle];
|
||||
sys_socket_t socketid = ipxsocket[handle];
|
||||
int ret;
|
||||
|
||||
ret = closesocket (socketid);
|
||||
|
@ -200,45 +199,46 @@ int WIPX_CloseSocket (int handle)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_Connect (int handle, struct qsockaddr *addr)
|
||||
int WIPX_Connect (sys_socket_t handle, struct qsockaddr *addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_CheckNewConnections (void)
|
||||
sys_socket_t WIPX_CheckNewConnections (void)
|
||||
{
|
||||
u_long available;
|
||||
|
||||
if (net_acceptsocket == -1)
|
||||
return -1;
|
||||
if (net_acceptsocket == INVALID_SOCKET)
|
||||
return INVALID_SOCKET;
|
||||
|
||||
if (ioctlsocket (ipxsocket[net_acceptsocket], FIONREAD, &available) == -1)
|
||||
Sys_Error ("WIPX: ioctlsocket (FIONREAD) failed\n");
|
||||
if (ioctlsocket (ipxsocket[net_acceptsocket], FIONREAD, &available) == SOCKET_ERROR)
|
||||
{
|
||||
Sys_Error ("WIPX: ioctlsocket (FIONREAD) failed");
|
||||
}
|
||||
if (available)
|
||||
return net_acceptsocket;
|
||||
return -1;
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
static byte packetBuffer[NET_DATAGRAMSIZE + 4];
|
||||
static byte netpacketBuffer[NET_DATAGRAMSIZE + 4];
|
||||
|
||||
int WIPX_Read (int handle, byte *buf, int len, struct qsockaddr *addr)
|
||||
int WIPX_Read (sys_socket_t handle, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int addrlen = sizeof(struct qsockaddr);
|
||||
int socketid = ipxsocket[handle];
|
||||
socklen_t addrlen = sizeof(struct qsockaddr);
|
||||
sys_socket_t socketid = ipxsocket[handle];
|
||||
int ret;
|
||||
|
||||
ret = recvfrom (socketid, (char *)packetBuffer, len+4, 0, (struct sockaddr *)addr, &addrlen);
|
||||
if (ret == -1)
|
||||
ret = recvfrom (socketid, (char *)netpacketBuffer, len+4, 0, (struct sockaddr *)addr, &addrlen);
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAEWOULDBLOCK || err == WSAECONNREFUSED)
|
||||
int err = SOCKETERRNO;
|
||||
if (err == EWOULDBLOCK || err == ECONNREFUSED)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -247,35 +247,38 @@ int WIPX_Read (int handle, byte *buf, int len, struct qsockaddr *addr)
|
|||
|
||||
// remove sequence number, it's only needed for DOS IPX
|
||||
ret -= 4;
|
||||
memcpy(buf, packetBuffer+4, ret);
|
||||
memcpy(buf, netpacketBuffer+4, ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_Broadcast (int handle, byte *buf, int len)
|
||||
int WIPX_Broadcast (sys_socket_t handle, byte *buf, int len)
|
||||
{
|
||||
return WIPX_Write (handle, buf, len, (struct qsockaddr *)&broadcastaddr);
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_Write (int handle, byte *buf, int len, struct qsockaddr *addr)
|
||||
int WIPX_Write (sys_socket_t handle, byte *buf, int len, struct qsockaddr *addr)
|
||||
{
|
||||
int socketid = ipxsocket[handle];
|
||||
sys_socket_t socketid = ipxsocket[handle];
|
||||
int ret;
|
||||
|
||||
// build packet with sequence number
|
||||
memcpy(&packetBuffer[0], &sequence[handle], 4);
|
||||
memcpy(&netpacketBuffer[0], &sequence[handle], 4);
|
||||
sequence[handle]++;
|
||||
memcpy(&packetBuffer[4], buf, len);
|
||||
memcpy(&netpacketBuffer[4], buf, len);
|
||||
len += 4;
|
||||
|
||||
ret = sendto (socketid, (char *)packetBuffer, len, 0, (struct sockaddr *)addr, sizeof(struct qsockaddr));
|
||||
if (ret == -1)
|
||||
if (WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
ret = sendto (socketid, (char *)netpacketBuffer, len, 0, (struct sockaddr *)addr, sizeof(struct qsockaddr));
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
int err = SOCKETERRNO;
|
||||
if (err == EWOULDBLOCK)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -341,16 +344,16 @@ int WIPX_StringToAddr (char *string, struct qsockaddr *addr)
|
|||
|
||||
//=============================================================================
|
||||
|
||||
int WIPX_GetSocketAddr (int handle, struct qsockaddr *addr)
|
||||
int WIPX_GetSocketAddr (sys_socket_t handle, struct qsockaddr *addr)
|
||||
{
|
||||
int socketid = ipxsocket[handle];
|
||||
int addrlen = sizeof(struct qsockaddr);
|
||||
sys_socket_t socketid = ipxsocket[handle];
|
||||
socklen_t addrlen = sizeof(struct qsockaddr);
|
||||
|
||||
Q_memset(addr, 0, sizeof(struct qsockaddr));
|
||||
if (getsockname(socketid, (struct sockaddr *)addr, &addrlen) != 0)
|
||||
{
|
||||
int err;
|
||||
err = WSAGetLastError();
|
||||
err = SOCKETERRNO;
|
||||
/* FIXME: what action should be taken?... */
|
||||
}
|
||||
|
||||
|
@ -398,13 +401,16 @@ int WIPX_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2)
|
|||
return -1;
|
||||
|
||||
if (*((struct sockaddr_ipx *)addr1)->sa_netnum && *((struct sockaddr_ipx *)addr2)->sa_netnum)
|
||||
{
|
||||
if (memcmp(((struct sockaddr_ipx *)addr1)->sa_netnum, ((struct sockaddr_ipx *)addr2)->sa_netnum, 4) != 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(((struct sockaddr_ipx *)addr1)->sa_nodenum, ((struct sockaddr_ipx *)addr2)->sa_nodenum, 6) != 0)
|
||||
return -1;
|
||||
|
||||
if (((struct sockaddr_ipx *)addr1)->sa_socket != ((struct sockaddr_ipx *)addr2)->sa_socket)
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -18,24 +18,25 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
// net_wipx.h
|
||||
|
||||
#ifndef __NET_WINIPX_H
|
||||
#define __NET_WINIPX_H
|
||||
|
||||
int WIPX_Init (void);
|
||||
sys_socket_t WIPX_Init (void);
|
||||
void WIPX_Shutdown (void);
|
||||
void WIPX_Listen (qboolean state);
|
||||
int WIPX_OpenSocket (int port);
|
||||
int WIPX_CloseSocket (int socketid);
|
||||
int WIPX_Connect (int socketid, struct qsockaddr *addr);
|
||||
int WIPX_CheckNewConnections (void);
|
||||
int WIPX_Read (int socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WIPX_Write (int socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WIPX_Broadcast (int socketid, byte *buf, int len);
|
||||
sys_socket_t WIPX_OpenSocket (int port);
|
||||
int WIPX_CloseSocket (sys_socket_t socketid);
|
||||
int WIPX_Connect (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
sys_socket_t WIPX_CheckNewConnections (void);
|
||||
int WIPX_Read (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WIPX_Write (sys_socket_t socketid, byte *buf, int len, struct qsockaddr *addr);
|
||||
int WIPX_Broadcast (sys_socket_t socketid, byte *buf, int len);
|
||||
char *WIPX_AddrToString (struct qsockaddr *addr);
|
||||
int WIPX_StringToAddr (char *string, struct qsockaddr *addr);
|
||||
int WIPX_GetSocketAddr (int socketid, struct qsockaddr *addr);
|
||||
int WIPX_GetSocketAddr (sys_socket_t socketid, struct qsockaddr *addr);
|
||||
int WIPX_GetNameFromAddr (struct qsockaddr *addr, char *name);
|
||||
int WIPX_GetAddrFromName (char *name, struct qsockaddr *addr);
|
||||
int WIPX_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2);
|
||||
|
|
Loading…
Reference in a new issue