X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=config%2Fcfgroot%2Fnetwork-functions.pl;h=5f53704cd18e552ca4f12670f6bce91449b62b54;hb=8bbcfa1152f87e8092c91284e25184ae52914e6d;hp=5559be5143212604dd50705780a5208e77089f8f;hpb=ff6cc71107ae50e913c87a9bc77b3af4b31ec932;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index 5559be5143..5f53704cd1 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -102,16 +102,19 @@ sub bin2ip($) { return $address; } -#Takes two network addresses and compares them against each other -#returns true if equal or false if not -sub network_equal{ +# Takes two network addresses, compares them against each other +# and returns true if equal or false if not +sub network_equal { my $network1 = shift; my $network2 = shift; + my $bin1 = &network2bin($network1); my $bin2 = &network2bin($network2); - if ($bin1 eq $bin2){ + + if ($bin1 eq $bin2) { return 1; } + return 0; } @@ -365,12 +368,26 @@ sub testsuite() { $result = &find_next_ip_address("1.2.3.4", 2); assert($result eq "1.2.3.6"); + $result = &network_equal("192.168.0.0/24", "192.168.0.0/255.255.255.0"); + assert($result); + + $result = &network_equal("192.168.0.0/24", "192.168.0.0/25"); + assert(!$result); + + $result = &network_equal("192.168.0.0/24", "192.168.0.128/25"); + assert(!$result); + + $result = &network_equal("192.168.0.1/24", "192.168.0.XXX/24"); + assert($result); + $result = &ip_address_in_network("10.0.1.4", "10.0.0.0/8"); assert($result); $result = &ip_address_in_network("192.168.30.11", "192.168.30.0/255.255.255.0"); assert($result); + print "Testsuite completed successfully!\n"; + return 0; }