FAQ
Edit report at https://pear.php.net/bugs/bug.php?id=18477&edit=1

ID: 18477
Updated by: daniel.oconnor@gmail.com
Reported By: phpipv6 at secureobscure dot com
Summary: compress returns blank with the unspecified address
(see RFC 4291)
-Status: Open
+Status: Feedback
Type: Bug
Package: Net_IPv6
Operating System: Ubuntu
Package Version: 1.2.1
PHP Version: 5.3.5
Roadmap Versions:
New Comment:

-Status: Open
+Status: Feedback
Can you by any chance do this against svn trunk? I applied the other
patch, but
now the line number count is a bit off.


Previous Comments:
------------------------------------------------------------------------

[2011-04-25 04:22:34] nosx

Added #patch bug:18477;patch:IPv6.php.diff;revision:1303705354;.

------------------------------------------------------------------------

[2011-04-25 04:18:09] nosx

Description:
------------
Calling the compress function on the text reperesentation of "the
unspecified address" returns blank output. The unspecified address is a
128-bit all zero address used to denote the ipv6 default route and a
host with an unknown address.
For more information see RFC 4291 Section 2.2.2
http://204.152.200.250/ipv6.php

Test script:
---------------
<?php
require_once 'Net/IPv6.php';
print
"\"".Net_IPv6::compress("0000:0000:0000:0000:0000:0000:0000:0000")."\"\n";
print "\"".Net_IPv6::compress("0:0:0:0:0:0:0:0")."\"\n";
print "\"".Net_IPv6::compress("::")."\"\n";
print "\"".Net_IPv6::compress("::",1)."\"\n";

print
"\"".Net_IPv6::compress("0000:0000:0000:0000:0000:0000:0000:0000/0")."\"\n";
print "\"".Net_IPv6::compress("0:0:0:0:0:0:0:0/0")."\"\n";
print "\"".Net_IPv6::compress("::/0")."\"\n";
print "\"".Net_IPv6::compress("::/0",1)."\"\n";
?>

Expected result:
----------------
"::"
"::"
"::"
"::"
"::/0"
"::/0"
"::/0"
"::/0"

Actual result:
--------------
""
""
"::"
""
"/0"
"/0"
"::/0"
"/0"

------------------------------------------------------------------------

Search Discussions

  • Phpipv6 at Jan 24, 2012 at 5:19 pm
    Edit report at https://pear.php.net/bugs/bug.php?id=18477&edit=1

    ID: 18477
    Comment by: phpipv6@secureobscure.com
    Reported By: phpipv6 at secureobscure dot com
    Summary: compress returns blank with the unspecified address
    (see RFC 4291)
    Status: Feedback
    Type: Bug
    Package: Net_IPv6
    Operating System: Ubuntu
    Package Version: 1.2.1
    PHP Version: 5.3.5
    Roadmap Versions:
    New Comment:

    This is a replacement compress function to resolve all the issues
    identified thus far, please see this in place of a differential patch:
    function compress($ip, $force = false)
    {
    if(false !== strpos($ip, '::')) { // its already compressed
    if(true == $force) {
    $ip = Net_IPv6::uncompress($ip);
    } else {
    return $ip;
    }
    }
    $prefix = Net_IPv6::getPrefixLength($ip);
    if (false === $prefix) {
    $prefix = '';
    } else {
    $ip = Net_IPv6::removePrefixLength($ip);
    $prefix = '/'.$prefix;
    }
    $netmask = Net_IPv6::getNetmaskSpec($ip);
    $ip = Net_IPv6::removeNetmaskSpec($ip);
    $ipp = explode(':', $ip);

    for ($i = 0; $i < count($ipp); $i++) {
    if(preg_match('/^[0-9a-fA-F]*$/',$ipp[$i]))
    {
    $ipp[$i] = dechex(hexdec($ipp[$i]));
    }else{
    //This hextet is NOT 0000-FFFF. Dont touch it.
    }
    }
    $cip = ':' . join(':', $ipp) . ':';

    //If the only characters in the IP are 0's and :'s just return
    "::".
    if (!preg_match('/[1-9a-fA-F]/',$cip)) {
    return "::".$prefix;
    }

    //Dont compress a single 16 bit :0: field into ::, must be 2
    :0:0: fields or longer.
    preg_match_all("/(:0)(: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);

    if ($netmask != "") {
    $cip = $cip.'/'.$netmask;
    }
    return $cip.$prefix;
    }


    Previous Comments:
    ------------------------------------------------------------------------

    [2012-01-24 12:54:39] doconnor

    -Status: Open
    +Status: Feedback
    Can you by any chance do this against svn trunk? I applied the other
    patch, but
    now the line number count is a bit off.

    ------------------------------------------------------------------------

    [2011-04-25 04:22:34] nosx

    Added #patch bug:18477;patch:IPv6.php.diff;revision:1303705354;.

    ------------------------------------------------------------------------

    [2011-04-25 04:18:09] nosx

    Description:
    ------------
    Calling the compress function on the text reperesentation of "the
    unspecified address" returns blank output. The unspecified address is a
    128-bit all zero address used to denote the ipv6 default route and a
    host with an unknown address.
    For more information see RFC 4291 Section 2.2.2
    http://204.152.200.250/ipv6.php

    Test script:
    ---------------
    <?php
    require_once 'Net/IPv6.php';
    print
    "\"".Net_IPv6::compress("0000:0000:0000:0000:0000:0000:0000:0000")."\"\n";
    print "\"".Net_IPv6::compress("0:0:0:0:0:0:0:0")."\"\n";
    print "\"".Net_IPv6::compress("::")."\"\n";
    print "\"".Net_IPv6::compress("::",1)."\"\n";

    print
    "\"".Net_IPv6::compress("0000:0000:0000:0000:0000:0000:0000:0000/0")."\"\n";
    print "\"".Net_IPv6::compress("0:0:0:0:0:0:0:0/0")."\"\n";
    print "\"".Net_IPv6::compress("::/0")."\"\n";
    print "\"".Net_IPv6::compress("::/0",1)."\"\n";
    ?>

    Expected result:
    ----------------
    "::"
    "::"
    "::"
    "::"
    "::/0"
    "::/0"
    "::/0"
    "::/0"

    Actual result:
    --------------
    ""
    ""
    "::"
    ""
    "/0"
    "/0"
    "::/0"
    "/0"

    ------------------------------------------------------------------------

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJan 24, '12 at 11:53a
activeJan 24, '12 at 5:19p
posts2
users2
websitepear.php.net

2 users in discussion

Daniel Oconnor: 1 post Phpipv6: 1 post

People

Translate

site design / logo © 2022 Grokbase