cl_main.c shouldn't look too closely at a netadr_t. curiosity killed the cat.

This commit is contained in:
Pontus Lidman 2000-06-14 19:55:05 +00:00
parent 87aa047299
commit 784f11bd9c
4 changed files with 21 additions and 26 deletions

View file

@ -94,10 +94,6 @@
#undef model_t #undef model_t
#endif #endif
#ifndef INADDR_LOOPBACK
# define INADDR_LOOPBACK (u_int32_t)0x7f000001
#endif
// we need to declare some mouse variables here, because the menu system // we need to declare some mouse variables here, because the menu system
// references them even when on a unix system. // references them even when on a unix system.
@ -450,29 +446,11 @@ void CL_ConnectionlessPacket (void)
Con_Printf ("client command\n"); Con_Printf ("client command\n");
#ifndef HAVE_IPV6 if (!NET_AdrIsLoopback(net_from) && !NET_CompareBaseAdr(net_from,net_local_adr)) {
if ((*(unsigned *)net_from.ip != *(unsigned *)net_local_adr.ip
&& *(unsigned *)net_from.ip != htonl(INADDR_LOOPBACK)) )
{
Con_Printf ("Command packet from remote host. Ignored.\n"); Con_Printf ("Command packet from remote host. Ignored.\n");
return; return;
} }
#else
if (memcmp(net_from.ip, net_local_adr.ip, sizeof(net_from.ip)) == 0)
;
else if (IN6_IS_ADDR_LOOPBACK((struct in6_addr *)net_from.ip))
;
else if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)net_from.ip) &&
((struct in_addr *)&net_from.ip[3])->s_addr == htonl(INADDR_LOOPBACK))
;
else {
Con_Printf ("Command packet from remote host. Ignored.\n");
return;
}
#endif
#ifdef _WIN32 #ifdef _WIN32
ShowWindow (mainwindow, SW_RESTORE); ShowWindow (mainwindow, SW_RESTORE);
SetForegroundWindow (mainwindow); SetForegroundWindow (mainwindow);

View file

@ -212,6 +212,7 @@ qboolean NET_GetPacket (void);
void NET_SendPacket (int length, void *data, netadr_t to); void NET_SendPacket (int length, void *data, netadr_t to);
qboolean NET_CompareAdr (netadr_t a, netadr_t b); qboolean NET_CompareAdr (netadr_t a, netadr_t b);
qboolean NET_AdrIsLoopback (netadr_t a);
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b); qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
char *NET_AdrToString (netadr_t a); char *NET_AdrToString (netadr_t a);
char *NET_BaseAdrToString (netadr_t a); char *NET_BaseAdrToString (netadr_t a);

View file

@ -113,6 +113,11 @@ void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a)
a->port = s->sin_port; a->port = s->sin_port;
} }
qboolean NET_AdrIsLoopback (netadr_t a)
{
return *(unsigned *)a.ip == htonl(INADDR_LOOPBACK);
}
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b) qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b)
{ {
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]) 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])

View file

@ -130,6 +130,17 @@ void SockadrToNetadr (struct sockaddr_in6 *s, netadr_t *a)
a->family = s->sin6_family; a->family = s->sin6_family;
} }
qboolean NET_AdrIsLoopback (netadr_t a)
{
if (IN6_IS_ADDR_LOOPBACK((struct in6_addr *)&a.ip))
return true;
else if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)&a.ip) &&
((struct in_addr *)&a.ip[3])->s_addr == htonl(INADDR_LOOPBACK))
return true;
return false;
}
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b) qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b)
{ {
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]) 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])