Fixed up ipv6 support a little. Addresses are more readable. Allows clients to connect. :P
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2964 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
073a9b9056
commit
f6d3e4ed94
1 changed files with 180 additions and 39 deletions
|
@ -132,7 +132,7 @@ int NetadrToSockadr (netadr_t *a, struct sockaddr_qstorage *s)
|
||||||
return sizeof(struct sockaddr_in6);
|
return sizeof(struct sockaddr_in6);
|
||||||
|
|
||||||
case NA_IPV6:
|
case NA_IPV6:
|
||||||
memset (s, 0, sizeof(struct sockaddr_in));
|
memset (s, 0, sizeof(struct sockaddr_in6));
|
||||||
((struct sockaddr_in6*)s)->sin6_family = AF_INET6;
|
((struct sockaddr_in6*)s)->sin6_family = AF_INET6;
|
||||||
|
|
||||||
memcpy(&((struct sockaddr_in6*)s)->sin6_addr, a->address.ip6, sizeof(struct in6_addr));
|
memcpy(&((struct sockaddr_in6*)s)->sin6_addr, a->address.ip6, sizeof(struct in6_addr));
|
||||||
|
@ -269,9 +269,60 @@ qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qboolean NET_AddressSmellsFunny(netadr_t a)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
//rejects certain blacklisted addresses
|
||||||
|
switch(a.type)
|
||||||
|
{
|
||||||
|
case NA_BROADCAST_IP:
|
||||||
|
case NA_IP:
|
||||||
|
//reject localhost
|
||||||
|
if (a.address.ip[0] == 127)// && a.address.ip[1] == 0 && a.address.ip[2] == 0 && a.address.ip[3] == 1 )
|
||||||
|
return true;
|
||||||
|
//'this' network (not an issue, but lets reject it anyway)
|
||||||
|
if (a.address.ip[0] == 0 && a.address.ip[1] == 0 && a.address.ip[2] == 0 && a.address.ip[3] == 0 )
|
||||||
|
return true;
|
||||||
|
//reject any broadcasts
|
||||||
|
if (a.address.ip[0] == 255 && a.address.ip[1] == 255 && a.address.ip[2] == 255 && a.address.ip[3] == 0 )
|
||||||
|
return true;
|
||||||
|
//not much else I can reject
|
||||||
|
return false;
|
||||||
|
|
||||||
|
#ifdef IPPROTO_IPV6
|
||||||
|
case NA_BROADCAST_IP6:
|
||||||
|
case NA_IPV6:
|
||||||
|
//reject [::XXXX] (this includes obsolete ipv4-compatible (not ipv4 mapped), and localhost)
|
||||||
|
for (i = 0; i < 12; i++)
|
||||||
|
if (a.address.ip6[i])
|
||||||
|
break;
|
||||||
|
if (i == 12)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USEIPX
|
||||||
|
//no idea how this protocol's addresses work
|
||||||
|
case NA_BROADCAST_IPX:
|
||||||
|
case NA_IPX:
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
case NA_LOOPBACK:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *NET_AdrToString (netadr_t a)
|
char *NET_AdrToString (netadr_t a)
|
||||||
{
|
{
|
||||||
|
qboolean doneblank;
|
||||||
|
char *p;
|
||||||
static char s[64];
|
static char s[64];
|
||||||
|
int i;
|
||||||
|
|
||||||
switch(a.type)
|
switch(a.type)
|
||||||
{
|
{
|
||||||
|
@ -287,23 +338,47 @@ char *NET_AdrToString (netadr_t a)
|
||||||
#ifdef IPPROTO_IPV6
|
#ifdef IPPROTO_IPV6
|
||||||
case NA_BROADCAST_IP6:
|
case NA_BROADCAST_IP6:
|
||||||
case NA_IPV6:
|
case NA_IPV6:
|
||||||
sprintf (s, "[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%i",
|
doneblank = false;
|
||||||
a.address.ip6[0],
|
p = s;
|
||||||
a.address.ip6[1],
|
sprintf (s, "[");
|
||||||
a.address.ip6[2],
|
p += strlen(p);
|
||||||
a.address.ip6[3],
|
|
||||||
a.address.ip6[4],
|
for (i = 0; i < 16; i+=2)
|
||||||
a.address.ip6[5],
|
{
|
||||||
a.address.ip6[6],
|
if (doneblank!=true && a.address.ip6[i] == 0 && a.address.ip6[i+1] == 0)
|
||||||
a.address.ip6[7],
|
{
|
||||||
a.address.ip6[8],
|
if (!doneblank)
|
||||||
a.address.ip6[9],
|
{
|
||||||
a.address.ip6[10],
|
sprintf (p, "::");
|
||||||
a.address.ip6[11],
|
p += strlen(p);
|
||||||
a.address.ip6[12],
|
doneblank = 2;
|
||||||
a.address.ip6[13],
|
}
|
||||||
a.address.ip6[14],
|
}
|
||||||
a.address.ip6[15],
|
else
|
||||||
|
{
|
||||||
|
if (doneblank==2)
|
||||||
|
doneblank = true;
|
||||||
|
else if (i != 0)
|
||||||
|
{
|
||||||
|
sprintf (p, ":");
|
||||||
|
p += strlen(p);
|
||||||
|
}
|
||||||
|
if (a.address.ip6[i+0])
|
||||||
|
{
|
||||||
|
sprintf (p, "%x%02x",
|
||||||
|
a.address.ip6[i+0],
|
||||||
|
a.address.ip6[i+1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf (p, "%x",
|
||||||
|
a.address.ip6[i+1]);
|
||||||
|
}
|
||||||
|
p += strlen(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf (p, "]:%i",
|
||||||
ntohs(a.port));
|
ntohs(a.port));
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
@ -337,7 +412,9 @@ char *NET_AdrToString (netadr_t a)
|
||||||
|
|
||||||
char *NET_BaseAdrToString (netadr_t a)
|
char *NET_BaseAdrToString (netadr_t a)
|
||||||
{
|
{
|
||||||
|
int i, doneblank;
|
||||||
static char s[64];
|
static char s[64];
|
||||||
|
char *p;
|
||||||
|
|
||||||
switch(a.type)
|
switch(a.type)
|
||||||
{
|
{
|
||||||
|
@ -352,23 +429,42 @@ char *NET_BaseAdrToString (netadr_t a)
|
||||||
#ifdef IPPROTO_IPV6
|
#ifdef IPPROTO_IPV6
|
||||||
case NA_BROADCAST_IP6:
|
case NA_BROADCAST_IP6:
|
||||||
case NA_IPV6:
|
case NA_IPV6:
|
||||||
sprintf (s, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
doneblank = false;
|
||||||
a.address.ip6[0],
|
p = s;
|
||||||
a.address.ip6[1],
|
for (i = 0; i < 16; i+=2)
|
||||||
a.address.ip6[2],
|
{
|
||||||
a.address.ip6[3],
|
if (doneblank!=true && a.address.ip6[i] == 0 && a.address.ip6[i+1] == 0)
|
||||||
a.address.ip6[4],
|
{
|
||||||
a.address.ip6[5],
|
if (!doneblank)
|
||||||
a.address.ip6[6],
|
{
|
||||||
a.address.ip6[7],
|
sprintf (p, "::");
|
||||||
a.address.ip6[8],
|
p += strlen(p);
|
||||||
a.address.ip6[9],
|
doneblank = 2;
|
||||||
a.address.ip6[10],
|
}
|
||||||
a.address.ip6[11],
|
}
|
||||||
a.address.ip6[12],
|
else
|
||||||
a.address.ip6[13],
|
{
|
||||||
a.address.ip6[14],
|
if (doneblank==2)
|
||||||
a.address.ip6[15]);
|
doneblank = true;
|
||||||
|
else if (i != 0)
|
||||||
|
{
|
||||||
|
sprintf (p, ":");
|
||||||
|
p += strlen(p);
|
||||||
|
}
|
||||||
|
if (a.address.ip6[i+0])
|
||||||
|
{
|
||||||
|
sprintf (p, "%x%02x",
|
||||||
|
a.address.ip6[i+0],
|
||||||
|
a.address.ip6[i+1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sprintf (p, "%x",
|
||||||
|
a.address.ip6[i+1]);
|
||||||
|
}
|
||||||
|
p += strlen(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USEIPX
|
#ifdef USEIPX
|
||||||
|
@ -785,14 +881,56 @@ qboolean NET_CompareAdrMasked(netadr_t a, netadr_t b, netadr_t mask)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// check to make sure all types match
|
//make sure the address being checked against matches the mask
|
||||||
if (a.type != b.type || a.type != mask.type)
|
if (b.type != mask.type)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// check port if both are non-zero
|
// check port if both are non-zero
|
||||||
if (a.port && b.port && a.port != b.port)
|
if (a.port && b.port && a.port != b.port)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// check to make sure all types match
|
||||||
|
if (a.type != b.type)
|
||||||
|
{
|
||||||
|
if (a.type == NA_IP && b.type == NA_IPV6)
|
||||||
|
{
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
#warning code me
|
||||||
|
#endif
|
||||||
|
//okay, comparing an ipv4 address against an ipv4-as-6
|
||||||
|
/* for (i = 0; i < 10; i++)
|
||||||
|
if (mask.address.ip[i] != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (; i < 12; i++)
|
||||||
|
{
|
||||||
|
if (mask.address.ip[i] != 0xff)
|
||||||
|
}
|
||||||
|
if (i == 12)
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
if (a.type == NA_IPV6 && b.type == NA_IP)
|
||||||
|
{
|
||||||
|
for (i = 0; i < 10; i++)
|
||||||
|
if (a.address.ip[i] != 0)
|
||||||
|
return false; //only matches if they're 0s, otherwise its not an ipv4 address there
|
||||||
|
|
||||||
|
for (; i < 12; i++)
|
||||||
|
if (a.address.ip[i] != 0xff && a.address.ip[i] != 0x00) //0x00 is depricated
|
||||||
|
return false; //only matches if they're 0s, otherwise its not an ipv4 address there
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if ((a.address.ip6[12+i] & mask.address.ip[i]) != (b.address.ip[i] & mask.address.ip[i]))
|
||||||
|
return false; //mask doesn't match
|
||||||
|
}
|
||||||
|
return true; //its an ipv4 address in there, the mask matched the whole way through
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// match on protocol type and compare address
|
// match on protocol type and compare address
|
||||||
switch (a.type)
|
switch (a.type)
|
||||||
{
|
{
|
||||||
|
@ -1949,8 +2087,11 @@ void NET_GetLocalAddress (int socket, netadr_t *out)
|
||||||
}
|
}
|
||||||
|
|
||||||
SockadrToNetadr(&address, out);
|
SockadrToNetadr(&address, out);
|
||||||
if (!*(int*)out->address.ip) //socket was set to auto
|
if (out->type == NA_IP)
|
||||||
*(int *)out->address.ip = *(int *)adr.address.ip; //change it to what the machine says it is, rather than the socket.
|
{
|
||||||
|
if (!*(int*)out->address.ip) //socket was set to auto
|
||||||
|
*(int *)out->address.ip = *(int *)adr.address.ip; //change it to what the machine says it is, rather than the socket.
|
||||||
|
}
|
||||||
|
|
||||||
if (notvalid)
|
if (notvalid)
|
||||||
Con_Printf("Couldn't detect local ip\n");
|
Con_Printf("Couldn't detect local ip\n");
|
||||||
|
|
Loading…
Reference in a new issue