Replace qsockaddr with AF_address_t.

It seems qsockaddr's assumptions aren't necessarily portable, as OpenBSD
seems to be doing weird things with qsa_family. Even if that's not the
case, this is cleaner.
This commit is contained in:
Bill Currie 2011-08-24 09:14:02 +09:00
parent 6fb6b0c4e4
commit 0d5bebabe2
9 changed files with 107 additions and 102 deletions

View file

@ -80,7 +80,7 @@ int UDP_CloseSocket (int socket);
\param addr The address to which very little will be done. \param addr The address to which very little will be done.
\return 0 \return 0
*/ */
int UDP_Connect (int socket, struct qsockaddr *addr); int UDP_Connect (int socket, AF_address_t *addr);
/** Check for incoming packets on the accept socket. /** Check for incoming packets on the accept socket.
@ -96,7 +96,7 @@ int UDP_CheckNewConnections (void);
\param[out] addr The address from which the packet originated. \param[out] addr The address from which the packet originated.
\return The number of bytes read or -1 on error. \return The number of bytes read or -1 on error.
*/ */
int UDP_Read (int socket, byte *buf, int len, struct qsockaddr *addr); int UDP_Read (int socket, byte *buf, int len, AF_address_t *addr);
/** Send a packet via the specified socket to the specified address. /** Send a packet via the specified socket to the specified address.
@ -106,7 +106,7 @@ int UDP_Read (int socket, byte *buf, int len, struct qsockaddr *addr);
\param addr The addres to which the packet will be sent. \param addr The addres to which the packet will be sent.
\return The number of bytes sent or -1 on error. \return The number of bytes sent or -1 on error.
*/ */
int UDP_Write (int socket, byte *buf, int len, struct qsockaddr *addr); int UDP_Write (int socket, byte *buf, int len, AF_address_t *addr);
/** Broadcast a packet via the specified socket. /** Broadcast a packet via the specified socket.
@ -130,7 +130,7 @@ int UDP_Broadcast (int socket, byte *buf, int len);
\param addr The address to convert. \param addr The address to convert.
\return The address in human readable form. \return The address in human readable form.
*/ */
const char *UDP_AddrToString (struct qsockaddr *addr); const char *UDP_AddrToString (AF_address_t *addr);
/** Retrieve the address to which the socket is bound. /** Retrieve the address to which the socket is bound.
@ -138,7 +138,7 @@ const char *UDP_AddrToString (struct qsockaddr *addr);
\param[out] addr The address to which the socket is bound. \param[out] addr The address to which the socket is bound.
\return 0 \return 0
*/ */
int UDP_GetSocketAddr (int socket, struct qsockaddr *addr); int UDP_GetSocketAddr (int socket, AF_address_t *addr);
/** Convert an address to a hostname. /** Convert an address to a hostname.
@ -147,7 +147,7 @@ int UDP_GetSocketAddr (int socket, struct qsockaddr *addr);
\bug No checking is done on the size of the buffer, and uses strcpy. \bug No checking is done on the size of the buffer, and uses strcpy.
*/ */
int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name); int UDP_GetNameFromAddr (AF_address_t *addr, char *name);
/** Convert a human readable address to a quake address. /** Convert a human readable address to a quake address.
@ -162,7 +162,7 @@ int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name);
\param addr The resulting address of the conversion. \param addr The resulting address of the conversion.
\return 0 if the conversion is successful, otherwise -1. \return 0 if the conversion is successful, otherwise -1.
*/ */
int UDP_GetAddrFromName (const char *name, struct qsockaddr *addr); int UDP_GetAddrFromName (const char *name, AF_address_t *addr);
/** Compare two network addresses. /** Compare two network addresses.
@ -177,14 +177,14 @@ int UDP_GetAddrFromName (const char *name, struct qsockaddr *addr);
is different. is different.
\return 0 if everything is the same. \return 0 if everything is the same.
*/ */
int UDP_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2); int UDP_AddrCompare (AF_address_t *addr1, AF_address_t *addr2);
/** Get the port number from the socket address. /** Get the port number from the socket address.
\param addr The socket address from which to retrieve the port number. \param addr The socket address from which to retrieve the port number.
\return The port number. \return The port number.
*/ */
int UDP_GetSocketPort (struct qsockaddr *addr); int UDP_GetSocketPort (AF_address_t *addr);
/** Set the port number of the socket address. /** Set the port number of the socket address.
@ -192,7 +192,7 @@ int UDP_GetSocketPort (struct qsockaddr *addr);
\param port The port number to which the socket address will be set. \param port The port number to which the socket address will be set.
\return 0 \return 0
*/ */
int UDP_SetSocketPort (struct qsockaddr *addr, int port); int UDP_SetSocketPort (AF_address_t *addr, int port);
//@} //@}

View file

@ -29,6 +29,15 @@
#ifndef __net_h #ifndef __net_h
#define __net_h #define __net_h
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
# define model_t sun_model_t
# include <netinet/in.h>
# undef model_t
#endif
#include "QF/quakeio.h" #include "QF/quakeio.h"
#include "QF/sizebuf.h" #include "QF/sizebuf.h"
@ -37,11 +46,14 @@
*/ */
//@{ //@{
struct qsockaddr { typedef union address {
short qsa_family; struct sockaddr_storage ss;
unsigned char qsa_data[14]; struct sockaddr sa;
}; struct sockaddr_in s4;
#ifdef HAVE_IPV6
struct sockaddr_in6 s6;
#endif
} AF_address_t;
#define NET_NAMELEN 64 #define NET_NAMELEN 64
@ -193,7 +205,7 @@ typedef struct qsocket_s {
/// \name socket address /// \name socket address
//@{ //@{
struct qsockaddr addr; AF_address_t addr;
char address[NET_NAMELEN]; ///< Human readable form. char address[NET_NAMELEN]; ///< Human readable form.
//@} //@}
} qsocket_t; } qsocket_t;
@ -254,7 +266,7 @@ typedef struct {
int maxusers; int maxusers;
int driver; int driver;
int ldriver; int ldriver;
struct qsockaddr addr; AF_address_t addr;
} hostcache_t; } hostcache_t;
extern int hostCacheCount; extern int hostCacheCount;
@ -401,18 +413,18 @@ typedef struct {
void (*Listen) (qboolean state); void (*Listen) (qboolean state);
int (*OpenSocket) (int port); int (*OpenSocket) (int port);
int (*CloseSocket) (int socket); int (*CloseSocket) (int socket);
int (*Connect) (int socket, struct qsockaddr *addr); int (*Connect) (int socket, AF_address_t *addr);
int (*CheckNewConnections) (void); int (*CheckNewConnections) (void);
int (*Read) (int socket, byte *buf, int len, struct qsockaddr *addr); int (*Read) (int socket, byte *buf, int len, AF_address_t *addr);
int (*Write) (int socket, byte *buf, int len, struct qsockaddr *addr); int (*Write) (int socket, byte *buf, int len, AF_address_t *addr);
int (*Broadcast) (int socket, byte *buf, int len); int (*Broadcast) (int socket, byte *buf, int len);
const char * (*AddrToString) (struct qsockaddr *addr); const char * (*AddrToString) (AF_address_t *addr);
int (*GetSocketAddr) (int socket, struct qsockaddr *addr); int (*GetSocketAddr) (int socket, AF_address_t *addr);
int (*GetNameFromAddr) (struct qsockaddr *addr, char *name); int (*GetNameFromAddr) (AF_address_t *addr, char *name);
int (*GetAddrFromName) (const char *name, struct qsockaddr *addr); int (*GetAddrFromName) (const char *name, AF_address_t *addr);
int (*AddrCompare) (struct qsockaddr *addr1, struct qsockaddr *addr2); int (*AddrCompare) (AF_address_t *addr1, AF_address_t *addr2);
int (*GetSocketPort) (struct qsockaddr *addr); int (*GetSocketPort) (AF_address_t *addr);
int (*SetSocketPort) (struct qsockaddr *addr, int port); int (*SetSocketPort) (AF_address_t *addr, int port);
} net_landriver_t; } net_landriver_t;
extern int net_numlandrivers; extern int net_numlandrivers;

View file

@ -299,7 +299,7 @@ Datagram_GetMessage (qsocket_t *sock)
unsigned int length; unsigned int length;
unsigned int flags; unsigned int flags;
int ret = 0; int ret = 0;
struct qsockaddr readaddr; AF_address_t readaddr;
unsigned int sequence; unsigned int sequence;
unsigned int count; unsigned int count;
@ -491,7 +491,7 @@ PollProcedure testPollProcedure = { NULL, 0.0, Test_Poll };
static void static void
Test_Poll (void *unused) Test_Poll (void *unused)
{ {
struct qsockaddr clientaddr; AF_address_t clientaddr;
int control; int control;
int len; int len;
char name[32]; //FIXME: overflow char name[32]; //FIXME: overflow
@ -552,7 +552,7 @@ Test_f (void)
const char *host; const char *host;
int n; int n;
int max = MAX_SCOREBOARD; int max = MAX_SCOREBOARD;
struct qsockaddr sendaddr; AF_address_t sendaddr;
if (testInProgress) if (testInProgress)
return; return;
@ -568,7 +568,7 @@ Test_f (void)
max = hostcache[n].maxusers; max = hostcache[n].maxusers;
memcpy (&sendaddr, &hostcache[n].addr, memcpy (&sendaddr, &hostcache[n].addr,
sizeof (struct qsockaddr)); sizeof (AF_address_t));
break; break;
} }
if (n < hostCacheCount) if (n < hostCacheCount)
@ -623,7 +623,7 @@ PollProcedure test2PollProcedure = { NULL, 0.0, Test2_Poll };
static void static void
Test2_Poll (void *unused) Test2_Poll (void *unused)
{ {
struct qsockaddr clientaddr; AF_address_t clientaddr;
int control; int control;
int len; int len;
char name[256]; //FIXME: overflow char name[256]; //FIXME: overflow
@ -689,7 +689,7 @@ Test2_f (void)
{ {
const char *host; const char *host;
int n; int n;
struct qsockaddr sendaddr; AF_address_t sendaddr;
if (test2InProgress) if (test2InProgress)
return; return;
@ -704,7 +704,7 @@ Test2_f (void)
net_landriverlevel = hostcache[n].ldriver; net_landriverlevel = hostcache[n].ldriver;
memcpy (&sendaddr, &hostcache[n].addr, memcpy (&sendaddr, &hostcache[n].addr,
sizeof (struct qsockaddr)); sizeof (AF_address_t));
break; break;
} }
if (n < hostCacheCount) if (n < hostCacheCount)
@ -814,8 +814,8 @@ Datagram_Listen (qboolean state)
static qsocket_t * static qsocket_t *
_Datagram_CheckNewConnections (void) _Datagram_CheckNewConnections (void)
{ {
struct qsockaddr clientaddr; AF_address_t clientaddr;
struct qsockaddr newaddr; AF_address_t newaddr;
int newsock; int newsock;
int acceptsock; int acceptsock;
qsocket_t *sock; qsocket_t *sock;
@ -977,10 +977,10 @@ _Datagram_CheckNewConnections (void)
} }
#ifdef BAN_TEST #ifdef BAN_TEST
// check for a ban // check for a ban
if (clientaddr.qsa_family == AF_INET) { if (clientaddr.sa.sa_family == AF_INET) {
unsigned testAddr; unsigned testAddr;
testAddr = ((struct sockaddr_in *) &clientaddr)->sin_addr.s_addr; testAddr = clientaddr.s4.sin_addr.s_addr;
if ((testAddr & banMask) == banAddr) { if ((testAddr & banMask) == banAddr) {
SZ_Clear (net_message->message); SZ_Clear (net_message->message);
// save space for the header, filled in later // save space for the header, filled in later
@ -1108,8 +1108,8 @@ _Datagram_SearchForHosts (qboolean xmit)
int ret; int ret;
int n; int n;
int i; int i;
struct qsockaddr readaddr; AF_address_t readaddr;
struct qsockaddr myaddr; AF_address_t myaddr;
int control; int control;
dfunc.GetSocketAddr (dfunc.controlSock, &myaddr); dfunc.GetSocketAddr (dfunc.controlSock, &myaddr);
@ -1180,7 +1180,7 @@ _Datagram_SearchForHosts (qboolean xmit)
strcpy (hostcache[n].name, "*"); strcpy (hostcache[n].name, "*");
strcat (hostcache[n].name, hostcache[n].cname); strcat (hostcache[n].name, hostcache[n].cname);
} }
memcpy (&hostcache[n].addr, &readaddr, sizeof (struct qsockaddr)); memcpy (&hostcache[n].addr, &readaddr, sizeof (AF_address_t));
hostcache[n].driver = net_driverlevel; hostcache[n].driver = net_driverlevel;
hostcache[n].ldriver = net_landriverlevel; hostcache[n].ldriver = net_landriverlevel;
@ -1219,8 +1219,8 @@ Datagram_SearchForHosts (qboolean xmit)
static qsocket_t * static qsocket_t *
_Datagram_Connect (const char *host) _Datagram_Connect (const char *host)
{ {
struct qsockaddr sendaddr; AF_address_t sendaddr;
struct qsockaddr readaddr; AF_address_t readaddr;
qsocket_t *sock; qsocket_t *sock;
int newsock; int newsock;
int ret; int ret;
@ -1275,9 +1275,9 @@ _Datagram_Connect (const char *host)
if (sfunc.AddrCompare (&readaddr, &sendaddr) != 0) { if (sfunc.AddrCompare (&readaddr, &sendaddr) != 0) {
Sys_MaskPrintf (SYS_NET, "%2d ", Sys_MaskPrintf (SYS_NET, "%2d ",
sfunc.AddrCompare (&readaddr, &sendaddr)); sfunc.AddrCompare (&readaddr, &sendaddr));
Sys_MaskPrintf (SYS_NET, "%d %s ", readaddr.qsa_family, Sys_MaskPrintf (SYS_NET, "%d %s ", readaddr.sa.sa_family,
sfunc.AddrToString (&readaddr)); sfunc.AddrToString (&readaddr));
Sys_MaskPrintf (SYS_NET, "%d %s\n", sendaddr.qsa_family, Sys_MaskPrintf (SYS_NET, "%d %s\n", sendaddr.sa.sa_family,
sfunc.AddrToString (&sendaddr)); sfunc.AddrToString (&sendaddr));
ret = 0; ret = 0;
continue; continue;
@ -1338,7 +1338,7 @@ _Datagram_Connect (const char *host)
} }
if (ret == CCREP_ACCEPT) { if (ret == CCREP_ACCEPT) {
memcpy (&sock->addr, &sendaddr, sizeof (struct qsockaddr)); memcpy (&sock->addr, &sendaddr, sizeof (AF_address_t));
dfunc.SetSocketPort (&sock->addr, MSG_ReadLong (net_message)); dfunc.SetSocketPort (&sock->addr, MSG_ReadLong (net_message));
} else { } else {

View file

@ -91,6 +91,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "compat.h" #include "compat.h"
#include "netmain.h" #include "netmain.h"
#include "net_udp.h"
#ifdef _WIN32 #ifdef _WIN32
# undef EWOULDBLOCK # undef EWOULDBLOCK
@ -115,12 +116,10 @@ static int net_acceptsocket = -1; // socket for fielding new
// connections // connections
static int net_controlsocket; static int net_controlsocket;
static int net_broadcastsocket = 0; static int net_broadcastsocket = 0;
static struct qsockaddr broadcastaddr; static AF_address_t broadcastaddr;
static uint32_t myAddr; static uint32_t myAddr;
#include "net_udp.h"
static int num_ifaces; static int num_ifaces;
uint32_t *ifaces; uint32_t *ifaces;
uint32_t *default_iface; uint32_t *default_iface;
@ -177,7 +176,7 @@ UDP_Init (void)
{ {
struct hostent *local; struct hostent *local;
char buff[MAXHOSTNAMELEN]; char buff[MAXHOSTNAMELEN];
struct qsockaddr addr; AF_address_t addr;
char *colon; char *colon;
#ifdef _WIN32 #ifdef _WIN32
WSADATA winsockdata; WSADATA winsockdata;
@ -318,7 +317,7 @@ UDP_CloseSocket (int socket)
the local network components to fill in the rest the local network components to fill in the rest
*/ */
static int static int
PartialIPAddress (const char *in, struct qsockaddr *hostaddr) PartialIPAddress (const char *in, AF_address_t *hostaddr)
{ {
char *buff; char *buff;
char *b; char *b;
@ -353,11 +352,9 @@ PartialIPAddress (const char *in, struct qsockaddr *hostaddr)
else else
port = net_hostport; port = net_hostport;
hostaddr->qsa_family = AF_INET; hostaddr->sa.sa_family = AF_INET;
((struct sockaddr_in *) hostaddr)->sin_port = htons ((short) port); hostaddr->s4.sin_port = htons ((short) port);
hostaddr->s4.sin_addr.s_addr = (myAddr & htonl (mask)) | htonl (addr);
((struct sockaddr_in *) hostaddr)->sin_addr.s_addr =
(myAddr & htonl (mask)) | htonl (addr);
free (buff); free (buff);
return 0; return 0;
@ -367,7 +364,7 @@ error:
} }
int int
UDP_Connect (int socket, struct qsockaddr *addr) UDP_Connect (int socket, AF_address_t *addr)
{ {
return 0; return 0;
} }
@ -376,8 +373,8 @@ int
UDP_CheckNewConnections (void) UDP_CheckNewConnections (void)
{ {
unsigned long available; unsigned long available;
struct sockaddr_in from; AF_address_t from;
socklen_t fromlen; socklen_t fromlen = sizeof (from);
char buff[1]; char buff[1];
if (net_acceptsocket == -1) if (net_acceptsocket == -1)
@ -397,7 +394,7 @@ UDP_CheckNewConnections (void)
} }
int int
UDP_Read (int socket, byte *buf, int len, struct qsockaddr *addr) UDP_Read (int socket, byte *buf, int len, AF_address_t *addr)
{ {
int ret; int ret;
#ifdef HAVE_IN_PKTINFO #ifdef HAVE_IN_PKTINFO
@ -438,7 +435,7 @@ UDP_Read (int socket, byte *buf, int len, struct qsockaddr *addr)
UDP_AddrToString (addr), info ? info->ipi_ifindex - 1 : -1, UDP_AddrToString (addr), info ? info->ipi_ifindex - 1 : -1,
last_iface ? inet_ntoa (info->ipi_addr) : "?"); last_iface ? inet_ntoa (info->ipi_addr) : "?");
#else #else
socklen_t addrlen = sizeof (struct qsockaddr); socklen_t addrlen = sizeof (AF_address_t);
ret = recvfrom (socket, buf, len, 0, (struct sockaddr *) addr, &addrlen); ret = recvfrom (socket, buf, len, 0, (struct sockaddr *) addr, &addrlen);
if (ret == -1 && (errno == EWOULDBLOCK || errno == ECONNREFUSED)) if (ret == -1 && (errno == EWOULDBLOCK || errno == ECONNREFUSED))
@ -483,12 +480,12 @@ UDP_Broadcast (int socket, byte *buf, int len)
} }
int int
UDP_Write (int socket, byte *buf, int len, struct qsockaddr *addr) UDP_Write (int socket, byte *buf, int len, AF_address_t *addr)
{ {
int ret; int ret;
ret = sendto (socket, buf, len, 0, (struct sockaddr *) addr, ret = sendto (socket, buf, len, 0, (struct sockaddr *) addr,
sizeof (struct qsockaddr)); sizeof (AF_address_t));
if (ret == -1 && errno == EWOULDBLOCK) if (ret == -1 && errno == EWOULDBLOCK)
return 0; return 0;
Sys_MaskPrintf (SYS_NET, "sent %d bytes to %s\n", ret, UDP_AddrToString (addr)); Sys_MaskPrintf (SYS_NET, "sent %d bytes to %s\n", ret, UDP_AddrToString (addr));
@ -496,7 +493,7 @@ UDP_Write (int socket, byte *buf, int len, struct qsockaddr *addr)
} }
const char * const char *
UDP_AddrToString (struct qsockaddr *addr) UDP_AddrToString (AF_address_t *addr)
{ {
static dstring_t *buffer; static dstring_t *buffer;
int haddr; int haddr;
@ -504,39 +501,38 @@ UDP_AddrToString (struct qsockaddr *addr)
if (!buffer) if (!buffer)
buffer = dstring_new (); buffer = dstring_new ();
haddr = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr); haddr = ntohl (addr->s4.sin_addr.s_addr);
dsprintf (buffer, "%d.%d.%d.%d:%d", (haddr >> 24) & 0xff, dsprintf (buffer, "%d.%d.%d.%d:%d", (haddr >> 24) & 0xff,
(haddr >> 16) & 0xff, (haddr >> 8) & 0xff, haddr & 0xff, (haddr >> 16) & 0xff, (haddr >> 8) & 0xff, haddr & 0xff,
ntohs (((struct sockaddr_in *) addr)->sin_port)); ntohs (addr->s4.sin_port));
return buffer->str; return buffer->str;
} }
int int
UDP_GetSocketAddr (int socket, struct qsockaddr *addr) UDP_GetSocketAddr (int socket, AF_address_t *addr)
{ {
unsigned int a; unsigned int a;
socklen_t addrlen = sizeof (struct qsockaddr); socklen_t addrlen = sizeof (AF_address_t);
memset (addr, 0, sizeof (struct qsockaddr)); memset (addr, 0, sizeof (AF_address_t));
getsockname (socket, (struct sockaddr *) addr, &addrlen); getsockname (socket, (struct sockaddr *) addr, &addrlen);
a = ((struct sockaddr_in *) addr)->sin_addr.s_addr; a = addr->s4.sin_addr.s_addr;
if (a == 0 || a == inet_addr ("127.0.0.1")) { if (a == 0 || a == inet_addr ("127.0.0.1")) {
((struct sockaddr_in *) addr)->sin_addr.s_addr = *default_iface; addr->s4.sin_addr.s_addr = *default_iface;
if (last_iface) if (last_iface)
((struct sockaddr_in *) addr)->sin_addr.s_addr = *last_iface; addr->s4.sin_addr.s_addr = *last_iface;
} }
return 0; return 0;
} }
int int
UDP_GetNameFromAddr (struct qsockaddr *addr, char *name) UDP_GetNameFromAddr (AF_address_t *addr, char *name)
{ {
struct hostent *hostentry; struct hostent *hostentry;
hostentry = hostentry = gethostbyaddr ((char *) &addr->s4.sin_addr,
gethostbyaddr ((char *) &((struct sockaddr_in *) addr)->sin_addr,
sizeof (struct in_addr), AF_INET); sizeof (struct in_addr), AF_INET);
if (hostentry) { if (hostentry) {
@ -549,7 +545,7 @@ UDP_GetNameFromAddr (struct qsockaddr *addr, char *name)
} }
int int
UDP_GetAddrFromName (const char *name, struct qsockaddr *addr) UDP_GetAddrFromName (const char *name, AF_address_t *addr)
{ {
struct hostent *hostentry; struct hostent *hostentry;
@ -560,41 +556,38 @@ UDP_GetAddrFromName (const char *name, struct qsockaddr *addr)
if (!hostentry) if (!hostentry)
return -1; return -1;
addr->qsa_family = AF_INET; addr->sa.sa_family = AF_INET;
((struct sockaddr_in *) addr)->sin_port = htons (net_hostport); addr->s4.sin_port = htons (net_hostport);
((struct sockaddr_in *) addr)->sin_addr.s_addr = addr->s4.sin_addr.s_addr = *(uint32_t *) hostentry->h_addr_list[0];
*(int *) hostentry->h_addr_list[0];
return 0; return 0;
} }
int int
UDP_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2) UDP_AddrCompare (AF_address_t *addr1, AF_address_t *addr2)
{ {
if (addr1->qsa_family != addr2->qsa_family) if (addr1->sa.sa_family != addr2->sa.sa_family)
return -2; return -2;
if (((struct sockaddr_in *) addr1)->sin_addr.s_addr != if (addr1->s4.sin_addr.s_addr != addr2->s4.sin_addr.s_addr)
((struct sockaddr_in *) addr2)->sin_addr.s_addr)
return -1; return -1;
if (((struct sockaddr_in *) addr1)->sin_port != if (addr1->s4.sin_port != addr2->s4.sin_port)
((struct sockaddr_in *) addr2)->sin_port)
return 1; return 1;
return 0; return 0;
} }
int int
UDP_GetSocketPort (struct qsockaddr *addr) UDP_GetSocketPort (AF_address_t *addr)
{ {
return ntohs (((struct sockaddr_in *) addr)->sin_port); return ntohs (addr->s4.sin_port);
} }
int int
UDP_SetSocketPort (struct qsockaddr *addr, int port) UDP_SetSocketPort (AF_address_t *addr, int port)
{ {
((struct sockaddr_in *) addr)->sin_port = htons (port); addr->s4.sin_port = htons (port);
return 0; return 0;
} }

View file

@ -100,7 +100,7 @@ startup (void)
} }
static void static void
shutdown (void) shutdown_f (void)
{ {
#ifndef _WIN32 #ifndef _WIN32
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
@ -131,7 +131,7 @@ SDL_main (int c, char **v)
#endif #endif
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();

View file

@ -62,7 +62,7 @@ static __attribute__ ((used)) const char rcsid[] =
qboolean isDedicated = false; qboolean isDedicated = false;
static void static void
shutdown (void) shutdown_f (void)
{ {
// change stdin to blocking // change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
@ -85,7 +85,7 @@ main (int c, const char *v[])
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();

View file

@ -60,7 +60,7 @@ qboolean isDedicated = true;
int nostdout = 0; int nostdout = 0;
static void static void
shutdown (void) shutdown_f (void)
{ {
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
fflush (stdout); fflush (stdout);
@ -95,7 +95,7 @@ main (int argc, const char **argv)
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();

View file

@ -112,7 +112,7 @@ startup (void)
} }
static void static void
shutdown (void) shutdown_f (void)
{ {
if (tevent) if (tevent)
CloseHandle (tevent); CloseHandle (tevent);
@ -214,7 +214,7 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
Host_Init (); Host_Init ();
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
oldtime = Sys_DoubleTime (); oldtime = Sys_DoubleTime ();

View file

@ -48,7 +48,7 @@ static __attribute__ ((used)) const char rcsid[] =
qboolean isDedicated = true; qboolean isDedicated = true;
static void static void
shutdown (void) shutdown_f (void)
{ {
} }
@ -84,7 +84,7 @@ main (int argc, const char **argv)
host_parms.argv = com_argv; host_parms.argv = com_argv;
Sys_RegisterShutdown (Host_Shutdown); Sys_RegisterShutdown (Host_Shutdown);
Sys_RegisterShutdown (shutdown); Sys_RegisterShutdown (shutdown_f);
Host_Init (); Host_Init ();