Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.5

Bug #7092 calculate function not working correctly
Submitted: 2006-03-10 19:06 UTC
From: brandon at homeisp dot com Assigned: fa
Status: Wont fix Package: Net_IPv4
PHP Version: 4.3.11 OS: Windows
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 38 - 14 = ?

 
 [2006-03-10 19:06 UTC] brandon at homeisp dot com (Brandon Petty)
Description: ------------ When calculating multiple broadcast and network address, the subnet does not change. I have also had quite a few other problems with calculate not giving the correct answers... but for now I will assume it is all related. thanks Test script: --------------- $ip_calc->ip = "1.1.1.60"; $ip_calc->netmask = "255.255.255.192"; $error = $ip_calc->calculate(); //echo "$error"; if(!is_object($error)) { echo "<br>IP: $ip_calc->ip & Sub: $ip_calc->netmask & network: $ip_calc->network & broadcast: $ip_calc->broadcast<br>"; } $ip_calc->ip = "1.1.1.250"; $ip_calc->netmask = "255.255.255.252"; $error = $ip_calc->calculate(); //echo "$error"; if(!is_object($error)) { echo "<br>IP: $ip_calc->ip & Sub: $ip_calc->netmask & network: $ip_calc->network & broadcast: $ip_calc->broadcast<br>"; } $ip_calc->ip = "1.1.1.80"; $ip_calc->netmask = "255.255.255.32"; $error = $ip_calc->calculate(); //echo "$error"; if(!is_object($error)) { echo "<br>IP: $ip_calc->ip & Sub: $ip_calc->netmask & network: $ip_calc->network & broadcast: $ip_calc->broadcast<br>"; } Expected result: ---------------- IP: 1.1.1.60 & Sub: 255.255.255.192 & network: 1.1.1.0 & broadcast: 1.1.1.63 IP: 1.1.1.250 & Sub: 255.255.255.252 & network: 1.1.1.248 & broadcast: 1.1.1.251 IP: 1.1.1.80 & Sub: 255.255.255.32 & network: NOT 1.1.1.64 & broadcast: NOT 1.1.1.127 Actual result: -------------- IP: 1.1.1.60 & Sub: 255.255.255.192 & network: 1.1.1.0 & broadcast: 1.1.1.63 IP: 1.1.1.250 & Sub: 255.255.255.192 & network: 1.1.1.192 & broadcast: 1.1.1.255 IP: 1.1.1.80 & Sub: 255.255.255.192 & network: 1.1.1.64 & broadcast: 1.1.1.127

Comments

 [2006-04-03 10:48 UTC] fa (Florian Anderiasch)
Thanks for reporting this. As it seems this issue is related to missing private variables in PHP4. Internally when you call calculate() there's a check for $this->netmask and $this->bitmask. The field not given is automatically populated. So when you set $this->netmask, $this->bitmask still holds the old value and is checked before $this->netmask. At the moment I'd advise you to recreate the object before doing a new calculation, but I'm trying to solve this without a BC break.
 [2006-04-03 12:06 UTC] fa (Florian Anderiasch)
At the moment Net_IPv4 only is able to use the "official" netmasks according to the RFC - which are /1 to /32 - and of your examples both "255.255.255.252" and "255.255.255.32" shouldn't work at all if I'm not mistaken. Nevertheless the aaforementioned bug exists and the only way I can think of a solution is to introduce 3 new methods named setIp("..."), setNetmask("...") and setBitmask("...") that you can use instead of $this->netmask="..." when you don't want to recreate the object