PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_IPv6 » Bug #3851

IPv4-mapped/compatible IPv6 uncompress bug

Details

Submitted2005-03-16 22:19 UTC
Fromdtaylor at jasi dot com
Assignedalexmerz
StatusClosed
PackageNet_IPv6
PHP Version4.3.10
OSSUSE Linux
Roadmaps(Not assigned)

Comments

[2005-03-16 22:19 UTC] dtaylor at jasi dot com

Description:
------------
Uncompressing an IPv4-mapped/compatible IPv6 address produced an address with 9 octets. The problem manifiests itself when splitting on '::' and counting the number of remaining ':'. An IPv4 address is actually 2 octets in an IPv6 address. This was not taken into account. The code below fixes that problem.

Reproduce code:
---------------
function Uncompress($ip) {

...

if(""==$ip2) {
$c2 = -1;
} else {
$pos = 0;
if(0 < ($pos = substr_count($ip2, ':'))) {
$c2 = $pos;
} else {
$c2 = 0;
}
}
//************************************************
// Account for ::FFFF:127.0.0.1 and ::127.0.0.1
// (IPv4-mapped/compatible IPv6 addresses)
if(strstr($ip2, '.')) {
$c2++;
}
//************************************************
if(-1 == $c1 && -1 == $c2) { // ::
$uip = "0:0:0:0:0:0:0:0";
} else if(-1==$c1) { // ::xxx
$fill = str_repeat('0:', 7-$c2);
$uip = str_replace('::', $fill, $uip);
} else if(-1==$c2) { // xxx::
$fill = str_repeat(':0', 7-$c1);
$uip = str_replace('::', $fill, $uip);
} else { // xxx::xxx
$fill = str_repeat(':0:', 6-$c2-$c1);
$uip = str_replace('::', $fill, $uip);
$uip = str_replace('::', ':', $uip);
}
}
return $uip;
}

[2005-03-17 09:12 UTC] alexmerz at php dot net

I will deal with it during the next days.

[2005-03-19 20:48 UTC] alexmerz at php dot net

Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pear.php.net/get/Net_IPv6