summaryrefslogtreecommitdiff
path: root/src/game/g_utils.c
diff options
context:
space:
mode:
authorM. Kristall <mkpdev@gmail.com>2010-03-01 01:11:56 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:17:29 +0000
commit117b2c94c3a8fafd9401112699158cbc81a89cd5 (patch)
treedd51952a3a0c3f36242bb837e917e4f7165002dc /src/game/g_utils.c
parentff82aefa975e52f1e25b090225b36645b57faa97 (diff)
* Prevent reparsing IP addresses for subnet bans
Diffstat (limited to 'src/game/g_utils.c')
-rw-r--r--src/game/g_utils.c38
1 files changed, 9 insertions, 29 deletions
diff --git a/src/game/g_utils.c b/src/game/g_utils.c
index 9de86337..1204a984 100644
--- a/src/game/g_utils.c
+++ b/src/game/g_utils.c
@@ -941,7 +941,7 @@ static const char *addr6parse( const char *str, addr_t *addr )
return str + i;
}
-qboolean G_AddressParse( const char *str, addr_t *addr, int *netmask )
+qboolean G_AddressParse( const char *str, addr_t *addr )
{
const char *p;
int max;
@@ -955,23 +955,20 @@ qboolean G_AddressParse( const char *str, addr_t *addr, int *netmask )
p = addr4parse( str, addr );
max = 32;
}
+ Q_strncpyz( addr->str, str, sizeof( addr->str ) );
if( !p )
return qfalse;
if( *p == '/' )
{
- if( netmask )
- {
- *netmask = atoi( p + 1 );
- if( *netmask < 1 || *netmask > max )
- *netmask = max;
- }
+ addr->mask = atoi( p + 1 );
+ if( addr->mask < 1 || addr->mask > max )
+ addr->mask = max;
}
else
{
if( *p )
return qfalse;
- if( netmask )
- *netmask = max;
+ addr->mask = max;
}
return qtrue;
}
@@ -983,11 +980,12 @@ G_AddressCompare
Based largely on NET_CompareBaseAdrMask from ioq3 revision 1557
===============
*/
-qboolean G_AddressCompare( const addr_t *a, const addr_t *b, int netmask )
+qboolean G_AddressCompare( const addr_t *a, const addr_t *b )
{
- int i;
+ int i, netmask;
if( a->type != b->type )
return qfalse;
+ netmask = a->mask;
if( a->type == IPv4 )
{
if( netmask < 1 || netmask > 32 )
@@ -1008,21 +1006,3 @@ qboolean G_AddressCompare( const addr_t *a, const addr_t *b, int netmask )
}
return qtrue;
}
-
-/*
-===============
-G_AdrCmpStr
-
-The first argument may be in CIDR notation
-===============
-*/
-qboolean G_AdrCmpStr( const char *a, const char *b )
-{
- int netmask = -1;
- addr_t cmpa, cmpb;
- if( !G_AddressParse( a, &cmpa, &netmask ) )
- return qfalse;
- if( !G_AddressParse( b, &cmpb, NULL ) )
- return qfalse;
- return G_AddressCompare( &cmpa, &cmpb, netmask );
-}