diff options
author | Urban Müller | 2025-04-10 14:20:55 +0200 |
---|---|---|
committer | Urban Müller | 2025-04-10 14:20:55 +0200 |
commit | e8b681292ae469a64df6033965babbe63be0290b (patch) | |
tree | f19d33d395e45dfcfdef4f8a839b4693884a47a2 | |
parent | eac020907afced2c33db53b564a80e4764dfe3b7 (diff) | |
download | itools-e8b681292ae469a64df6033965babbe63be0290b.tar.gz itools-e8b681292ae469a64df6033965babbe63be0290b.tar.bz2 itools-e8b681292ae469a64df6033965babbe63be0290b.zip |
return matching CIDR for tracking
-rw-r--r-- | it.class | 2 | ||||
-rwxr-xr-x | test/it.t | 14 |
2 files changed, 8 insertions, 8 deletions
@@ -423,7 +423,7 @@ static function cidr_match($ip, $cidrs) $lastbyte_matched = $bitmask ? (ord($ip_bin[$valid_bytes]) & $bitmask) == (ord($subnet_bin[$valid_bytes]) & $bitmask) : true; if (substr($ip_bin, 0, $valid_bytes) == substr($subnet_bin, 0, $valid_bytes) && $lastbyte_matched) - return true; + return $cidr; } return false; @@ -323,17 +323,17 @@ ini_set('default_charset', $oldcharset); # end of tests that must run with speci # it::cidr_match tests is(it::cidr_match('192.168.2.3', '192.168.2.5'), false, "cidr_match full IP no match no mask"); -is(it::cidr_match('192.168.2.3', '192.168.2.3'), true, "cidr_match full IP match no mask"); +is(it::cidr_match('192.168.2.3', '192.168.2.3'), '192.168.2.3', "cidr_match full IP match no mask"); is(it::cidr_match('192.168.2.3', '192.168.2.5/32'), false, "cidr_match full IP no match"); -is(it::cidr_match('192.168.2.5', '192.168.2.5/32'), true, "cidr_match full IP match"); +is(it::cidr_match('192.168.2.5', '192.168.2.5/32'), '192.168.2.5/32', "cidr_match full IP match"); is(it::cidr_match('192.168.1.1', '192.168.42.0/24'), false, "cidr_match no match"); -is(it::cidr_match('192.168.42.1', '192.168.42.0/24'), true, "cidr_match basic match"); -is(it::cidr_match('192.168.42.42', '192.168.0.0/16'), true, "cidr_match class b"); +is(it::cidr_match('192.168.42.1', '192.168.42.0/24'), '192.168.42.0/24', "cidr_match basic match"); +is(it::cidr_match('192.168.42.42', '192.168.0.0/16'), '192.168.0.0/16', "cidr_match class b"); is(it::cidr_match('192.168.42.42', '192.168.42.64/26'), false, "cidr_match offset no match"); -is(it::cidr_match('192.168.42.42', '192.168.42.32/27'), true, "cidr_match offset"); -is(it::cidr_match('2001:918:ff83:101:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), true, "cidr_match ipv6"); +is(it::cidr_match('192.168.42.42', '192.168.42.32/27'), '192.168.42.32/27', "cidr_match offset"); +is(it::cidr_match('2001:918:ff83:101:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), '2001:918:ff83:101::/64', "cidr_match ipv6"); is(it::cidr_match('2001:918:ff83:102:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), false, "cidr_match ipv6 no match" ); -is(it::cidr_match('10.11.12.13', ['10.0.0.0/8', '192.168.0.0./16']), true, "cidr_match array"); +is(it::cidr_match('10.11.12.13', ['10.0.0.0/8', '192.168.0.0./16']), '10.0.0.0/8', "cidr_match array"); # it::is_private_ip tests is(it::is_private_ip('192.168.2.3'), true, "is_private_ip 192.168/16 example"); |