CIDR's actually working would be nice. That's what I get for assuming the output from a different func would be correct.

When banning checked accounts, it should only tag and comment the checked ones, not all of them in the list.
Optimizing firewall.
This commit is contained in:
asayre 2007-02-10 08:21:13 +00:00
parent 318ad5f08c
commit 75e8798c18
4 changed files with 254 additions and 49 deletions

View file

@ -128,7 +128,7 @@ namespace Server
{
string[] str = cidr.Split( '/' );
if ( str.Length < 2 )
if ( str.Length != 2 )
return false;
IPAddress cidrPrefix;
@ -151,12 +151,26 @@ namespace Server
uint mask = uint.MaxValue << cidrLength;
long cidrValue = Utility.GetLongAddressValue( cidrPrefix );
long ipValue = Utility.GetLongAddressValue( ip );
uint cidrValue = Utility.OrderedAddressValue( cidrPrefix );
uint ipValue = Utility.OrderedAddressValue( ip );
return ( ( cidrValue & mask ) == ( ipValue & mask ) );
}
private static uint OrderedAddressValue( IPAddress address )
{
uint value = 0;
byte[] bytes = address.GetAddressBytes();
for( int i=0; i < bytes.Length; i++ )
{
value |= ((uint)bytes[i]) << (bytes.Length-1 -i)*8;
}
return value;
}
public static bool IPMatch( string val, IPAddress ip, ref bool valid )
{
valid = true;
@ -256,7 +270,7 @@ namespace Server
}
else
{
valid = false;
valid = false; //high & lowpart would be 0 if it got to here.
}
}
}
@ -321,24 +335,6 @@ namespace Server
int.TryParse( value, out i );
return i;
/*
try
{
if ( value.StartsWith( "0x" ) )
{
return Convert.ToInt32( value.Substring( 2 ), 16 );
}
else
{
return Convert.ToInt32( value );
}
}
catch
{
return 0;
}
* */
}
#endregion