Basic IPv6 support. Some inspiration from the patches by Lubos Dolezel and JF Tremblay at https://bugzilla.icculus.org/show_bug.cgi?id=2355.
This commit is contained in:
parent
c5980568e1
commit
5d63a38ad9
8 changed files with 926 additions and 481 deletions
|
@ -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 {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -136,7 +136,9 @@ typedef enum {
|
|||
NA_BAD, // an address lookup failed
|
||||
NA_LOOPBACK,
|
||||
NA_BROADCAST,
|
||||
NA_IP
|
||||
NA_IP,
|
||||
NA_IP6,
|
||||
NA_UNSPEC
|
||||
} netadrtype_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -144,10 +146,12 @@ typedef enum {
|
|||
NS_SERVER
|
||||
} netsrc_t;
|
||||
|
||||
#define NET_ADDRSTRMAXLEN 48 // maximum length of an IPv6 address string including trailing '\0'
|
||||
typedef struct {
|
||||
netadrtype_t type;
|
||||
|
||||
byte ip[4];
|
||||
byte ip6[16];
|
||||
|
||||
unsigned short port;
|
||||
} netadr_t;
|
||||
|
@ -165,7 +169,8 @@ qboolean NET_CompareAdr (netadr_t a, netadr_t b);
|
|||
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
|
||||
qboolean NET_IsLocalAddress (netadr_t adr);
|
||||
const char *NET_AdrToString (netadr_t a);
|
||||
qboolean NET_StringToAdr ( const char *s, netadr_t *a);
|
||||
const char *NET_AdrToStringwPort (netadr_t a);
|
||||
qboolean NET_StringToAdr ( const char *s, netadr_t *a, netadrtype_t family);
|
||||
qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
|
||||
void NET_Sleep(int msec);
|
||||
|
||||
|
@ -1015,7 +1020,7 @@ void Sys_SetErrorText( const char *text );
|
|||
void Sys_SendPacket( int length, const void *data, netadr_t to );
|
||||
qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message );
|
||||
|
||||
qboolean Sys_StringToAdr( const char *s, netadr_t *a );
|
||||
qboolean Sys_StringToAdr( const char *s, netadr_t *a, netadrtype_t family );
|
||||
//Does NOT parse port numbers, only base addresses.
|
||||
|
||||
qboolean Sys_IsLANAddress (netadr_t adr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue