]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
General-functions.pl: rewrite getnetworkip without inet_aton
authorAlexander Marx <alexander.marx@ipfire.org>
Thu, 8 May 2014 12:31:31 +0000 (14:31 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 19 Jun 2014 10:11:47 +0000 (12:11 +0200)
config/cfgroot/general-functions.pl

index a3f4311000ae89031c5667fa46969fb8ac3a09ce..6fabf1c0583a0c9c2e5fa90f4966028671dffae0 100644 (file)
@@ -413,9 +413,9 @@ sub getnetworkip
        #Gets:  IP, CIDR    (10.10.10.0-255, 24)
        #Gives:  10.10.10.0
        my ($ccdip,$ccdsubnet) = @_;
-       my $ip_address_binary = inet_aton( $ccdip );
-       my $netmask_binary    = ~pack("N", (2**(32-$ccdsubnet))-1);
-       my $network_address    = inet_ntoa( $ip_address_binary & $netmask_binary );
+       my $ip_address_binary = &Socket::inet_pton( AF_INET,$ccdip );
+       my $netmask_binary = &Socket::inet_pton(AF_INET,&iporsubtodec($ccdsubnet));
+       my $network_address    = &Socket::inet_ntop( AF_INET,$ip_address_binary & $netmask_binary );
        return $network_address;
 }