summaryrefslogtreecommitdiff
path: root/src/qcommon/net_chan.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2009-10-03 11:52:53 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:15:28 +0000
commitb47a49a03370e7ea42f47623b9f72a5ca799f0e7 (patch)
tree9d64d778ded2971d7ebd05970d903d886bd81436 /src/qcommon/net_chan.c
parent09ceb08b95978feb0a9b737f22ac0f662c7465d6 (diff)
* Merge ioq3-r1423
+ IPv6 + VoIP + Stereo rendering + Other minor stuff
Diffstat (limited to 'src/qcommon/net_chan.c')
-rw-r--r--src/qcommon/net_chan.c139
1 files changed, 48 insertions, 91 deletions
diff --git a/src/qcommon/net_chan.c b/src/qcommon/net_chan.c
index aba3b96d..246cd0b0 100644
--- a/src/qcommon/net_chan.c
+++ b/src/qcommon/net_chan.c
@@ -461,71 +461,6 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) {
//==============================================================================
-/*
-===================
-NET_CompareBaseAdr
-
-Compares without the port
-===================
-*/
-qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b)
-{
- if (a.type != b.type)
- return qfalse;
-
- if (a.type == NA_LOOPBACK)
- return qtrue;
-
- if (a.type == NA_IP)
- {
- if (a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3])
- return qtrue;
- return qfalse;
- }
-
- Com_Printf ("NET_CompareBaseAdr: bad address type\n");
- return qfalse;
-}
-
-const char *NET_AdrToString (netadr_t a)
-{
- static char s[64];
-
- if (a.type == NA_LOOPBACK) {
- Com_sprintf (s, sizeof(s), "loopback");
- } else if (a.type == NA_IP) {
- Com_sprintf (s, sizeof(s), "%i.%i.%i.%i:%hu",
- a.ip[0], a.ip[1], a.ip[2], a.ip[3], BigShort(a.port));
- }
-
- return s;
-}
-
-
-qboolean NET_CompareAdr (netadr_t a, netadr_t b)
-{
- if (a.type != b.type)
- return qfalse;
-
- if (a.type == NA_LOOPBACK)
- return qtrue;
-
- if (a.type == NA_IP)
- {
- if (a.ip[0] == b.ip[0] && a.ip[1] == b.ip[1] && a.ip[2] == b.ip[2] && a.ip[3] == b.ip[3] && a.port == b.port)
- return qtrue;
- return qfalse;
- }
-
- Com_Printf ("NET_CompareAdr: bad address type\n");
- return qfalse;
-}
-
-
-qboolean NET_IsLocalAddress( netadr_t adr ) {
- return adr.type == NA_LOOPBACK;
-}
-
/*
@@ -737,46 +672,68 @@ void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len
NET_StringToAdr
Traps "localhost" for loopback, passes everything else to system
+return 0 on address not found, 1 on address found with port, 2 on address found without port.
=============
*/
-qboolean NET_StringToAdr( const char *s, netadr_t *a ) {
- qboolean r;
- char base[MAX_STRING_CHARS];
- char *port;
+int NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family )
+{
+ char base[MAX_STRING_CHARS], *search;
+ char *port = NULL;
if (!strcmp (s, "localhost")) {
Com_Memset (a, 0, sizeof(*a));
a->type = NA_LOOPBACK;
- return qtrue;
+// as NA_LOOPBACK doesn't require ports report port was given.
+ return 1;
}
- // look for a port number
Q_strncpyz( base, s, sizeof( base ) );
- port = strstr( base, ":" );
- if ( port ) {
- *port = 0;
- port++;
+
+ if(*base == '[' || Q_CountChar(base, ':') > 1)
+ {
+ // This is an ipv6 address, handle it specially.
+ search = strchr(base, ']');
+ if(search)
+ {
+ *search = '\0';
+ search++;
+
+ if(*search == ':')
+ port = search + 1;
+ }
+
+ if(*base == '[')
+ search = base + 1;
+ else
+ search = base;
}
-
- r = Sys_StringToAdr( base, a );
-
- if ( !r ) {
- a->type = NA_BAD;
- return qfalse;
+ else
+ {
+ // look for a port number
+ port = strchr( base, ':' );
+
+ if ( port ) {
+ *port = '\0';
+ port++;
+ }
+
+ search = base;
}
- // inet_addr returns this if out of range
- if ( a->ip[0] == 255 && a->ip[1] == 255 && a->ip[2] == 255 && a->ip[3] == 255 ) {
+ if(!Sys_StringToAdr(search, a, family))
+ {
a->type = NA_BAD;
- return qfalse;
+ return 0;
}
- if ( port ) {
- a->port = BigShort( (short)atoi( port ) );
- } else {
- a->port = BigShort( PORT_SERVER );
+ if(port)
+ {
+ a->port = BigShort((short) atoi(port));
+ return 1;
+ }
+ else
+ {
+ a->port = BigShort(PORT_SERVER);
+ return 2;
}
-
- return qtrue;
}
-