From 784f11bd9c5954a17c0a4ee2dca1eb0ff4ec597c Mon Sep 17 00:00:00 2001 From: Pontus Lidman Date: Wed, 14 Jun 2000 19:55:05 +0000 Subject: [PATCH] cl_main.c shouldn't look too closely at a netadr_t. curiosity killed the cat. --- common/cl_main.c | 30 ++++-------------------------- common/net.h | 1 + common/net_udp.c | 5 +++++ common/net_udp6.c | 11 +++++++++++ 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/common/cl_main.c b/common/cl_main.c index ac8def8..982728b 100644 --- a/common/cl_main.c +++ b/common/cl_main.c @@ -94,10 +94,6 @@ #undef model_t #endif -#ifndef INADDR_LOOPBACK -# define INADDR_LOOPBACK (u_int32_t)0x7f000001 -#endif - // we need to declare some mouse variables here, because the menu system // references them even when on a unix system. @@ -450,28 +446,10 @@ void CL_ConnectionlessPacket (void) Con_Printf ("client command\n"); -#ifndef HAVE_IPV6 - 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"); - 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 + if (!NET_AdrIsLoopback(net_from) && !NET_CompareBaseAdr(net_from,net_local_adr)) { + Con_Printf ("Command packet from remote host. Ignored.\n"); + return; + } #ifdef _WIN32 ShowWindow (mainwindow, SW_RESTORE); diff --git a/common/net.h b/common/net.h index 034ba23..936b9fe 100644 --- a/common/net.h +++ b/common/net.h @@ -212,6 +212,7 @@ qboolean NET_GetPacket (void); void NET_SendPacket (int length, void *data, netadr_t to); qboolean NET_CompareAdr (netadr_t a, netadr_t b); +qboolean NET_AdrIsLoopback (netadr_t a); qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b); char *NET_AdrToString (netadr_t a); char *NET_BaseAdrToString (netadr_t a); diff --git a/common/net_udp.c b/common/net_udp.c index cf6c226..a6fb54d 100644 --- a/common/net_udp.c +++ b/common/net_udp.c @@ -113,6 +113,11 @@ void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a) 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) { 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]) diff --git a/common/net_udp6.c b/common/net_udp6.c index 2298c38..4c0db84 100644 --- a/common/net_udp6.c +++ b/common/net_udp6.c @@ -130,6 +130,17 @@ void SockadrToNetadr (struct sockaddr_in6 *s, netadr_t *a) 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) { 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])