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

Bug #12442 Net_IPv6::Compress method confuses subnet for an ipv6 part
Submitted: 2007-11-14 12:46 UTC
From: erikdebruijn Assigned: alexmerz
Status: Closed Package: Net_IPv6 (version 1.1.0RC2)
PHP Version: 5.2.0 OS: Debian GNU/Linux Etch
Roadmaps: (Not assigned)    
Subscription  


 [2007-11-14 12:46 UTC] erikdebruijn (Erik De Bruijn)
Description: ------------ Hi on my BudgetDedicated VPS (which includes native IPv6 for free!) I found out about a problem. It is in Net_IPv6::Compress. A simplified script, such as the following doesn't handle the subnet apropriately: <?php function IPv6removeNetmaskSpec($ip) { if(false !== strpos($ip, '/')) { list($addr, $nm) = explode('/', $ip); } else { $addr = $ip; } return $addr; } function IPv6Compress($ip) { $cip = IPv6removeNetmaskSpec($ip); if (!strstr($ip, '::')) { $ipp = explode(':',$ip); for($i=0; $i<count($ipp); $i++) { $ipp[$i] = dechex(hexdec($ipp[$i])); } $cip = ':' . join(':',$ipp) . ':'; preg_match_all("/(:0)+/", $cip, $zeros); if (count($zeros[0])>0) { $match = ''; foreach($zeros[0] as $zero) { if (strlen($zero) > strlen($match)) $match = $zero; } $cip = preg_replace('/' . $match . '/', ':', $cip, 1); } $cip = preg_replace('/((^:)|(:$))/', '' ,$cip); $cip = preg_replace('/((^:)|(:$))/', '::' ,$cip); } return $cip; } echo $ip = "2001:4de0:aaac:0000:3744:0000:0000:0000/120"; echo " (INPUT)"; echo "\n".IPv6Compress($ip)." (OUTPUT)"; /*OUTPUT of # php /tmp/testscript.php 2001:4abc:abcd:0000:3744:0000:0000:0000/120 (INPUT) 2001:4abc:abcd:0:3744::120 (OUTPUT) N.B. This is A DIFFERENT IP ADDRESS after compression! */ ?> Get your own IPv6 server here: https://www.budgetdedicated.com/ipv6.php Test script: --------------- My (pseudo-) patch: < $cip = IPv6removeNetmaskSpec($ip); > $cip = IPv6removeNetmaskSpec($cip); and a line needs to be added to append the subnet to the compressed version. This could be as simple as replacing: < return $cip; with: > return $cip.substr($ip,strpos($ip, '/')); The output then becomes: 2001:4abc:abcd:0000:3744:0000:0000:0000/120 (INPUT) 2001:4abc:abcd:0:3744::/120 (OUTPUT) Expected result: ---------------- The 120 should not be there, it should be /120 or not there at all. IMHO, if a netmask is given, it should be added again after compressing it. IMHO it should output: 2001:4abc:abcd:0000:3744:0000:0000:0000/120 (INPUT) 2001:4abc:abcd:0:3744::/120 (OUTPUT) Actual result: -------------- OUTPUT of # php /tmp/testscript.php 2001:4abc:abcd:0000:3744:0000:0000:0000/120 (INPUT) 2001:4abc:abcd:0:3744::120 (OUTPUT)

Comments

 [2007-11-14 12:50 UTC] erikdebruijn (Erik De Bruijn)
All of the prefixes in this example should have been 2001:4abc:abcd, but I missed a few when replacing the orriginal IP with a fake IP. :)
 [2007-11-15 10:36 UTC] alexmerz (Alexander Merz)
This bug leads to some more problems while working on a fix. A complete fix is in progress.
 [2007-11-16 00:26 UTC] alexmerz (Alexander Merz)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.