diff options
Diffstat (limited to 'code/qcommon/net_chan.c')
-rw-r--r-- | code/qcommon/net_chan.c | 112 |
1 files changed, 30 insertions, 82 deletions
diff --git a/code/qcommon/net_chan.c b/code/qcommon/net_chan.c index 6458444..ac7b30b 100644 --- a/code/qcommon/net_chan.c +++ b/code/qcommon/net_chan.c @@ -460,74 +460,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_BOT) { - Com_sprintf (s, sizeof(s), "bot"); - } 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; -} - - /* ============================================================================= @@ -743,10 +675,10 @@ NET_StringToAdr Traps "localhost" for loopback, passes everything else to system ============= */ -qboolean NET_StringToAdr( const char *s, netadr_t *a ) { +qboolean NET_StringToAdr( const char *s, netadr_t *a, netadrtype_t family ) { qboolean r; - char base[MAX_STRING_CHARS]; - char *port; + char base[MAX_STRING_CHARS], *search; + char *port = NULL; if (!strcmp (s, "localhost")) { Com_Memset (a, 0, sizeof(*a)); @@ -756,25 +688,41 @@ qboolean NET_StringToAdr( const char *s, netadr_t *a ) { // look for a port number Q_strncpyz( base, s, sizeof( base ) ); - port = strstr( base, ":" ); - if ( port ) { - *port = 0; - port++; + + if(*base == '[') + { + // This is an ipv6 address, handle it specially. + search = strchr(base, ']'); + if(search) + { + *search = '\0'; + search++; + + if(*search == ':') + port = search + 1; + } + + search = base + 1; + } + else + { + port = strchr( base, ':' ); + + if ( port ) { + *port = '\0'; + port++; + } + + search = base; } - r = Sys_StringToAdr( base, a ); + r = Sys_StringToAdr( search, a, family ); if ( !r ) { a->type = NA_BAD; return qfalse; } - // 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 ) { - a->type = NA_BAD; - return qfalse; - } - if ( port ) { a->port = BigShort( (short)atoi( port ) ); } else { |