From 117b2c94c3a8fafd9401112699158cbc81a89cd5 Mon Sep 17 00:00:00 2001 From: "M. Kristall" Date: Mon, 1 Mar 2010 01:11:56 +0000 Subject: * Prevent reparsing IP addresses for subnet bans --- src/game/g_utils.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/game/g_utils.c') 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 ); -} -- cgit