[PEAR-BUG] Req #18687 [Opn]: support RFC5952 compatible format

[email protected]
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=18687&edit=1

 ID:               18687
 Updated by:       [email protected]
 Reported By:      koyama at hoge dot org
 Summary:          support RFC5952 compatible format
 Status:           Open
 Type:             Feature/Change Request
 Package:          Net_IPv6
 Operating System: CentOS
 Package Version:  1.2.1
 PHP Version:      5.3.6
-Assigned To:      
+Assigned To:      alexmerz
 Roadmap Versions: 
 New Comment:

-Assigned To:
+Assigned To: alexmerz



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

[2011-07-26 13:58:28] koyama

Uploading a patch is not working. paste here.

--- IPv6.php    2011-07-26 20:38:19.000000000 +0900
+++ IPv6.php.new        2011-07-26 20:37:46.000000000 +0900
@@ -748,6 +748,32 @@
     }
 
     // }}}
+    // {{{ recommendedFormat()
+    /**
+     * represent IPv6 address in RFC5952 format.
+     *
+     * @param String  $ip a valid IPv6-adress (hex format)
+     *
+     * @return String the recommended representation of IPv6-adress
(hex format)
+     * @access public
+     * @see    compress()
+     * @static
+     * @author koyama at hoge dot org
+     */
+    function recommendedFormat($ip)
+    {
+        $compressed = self::compress($ip, true);
+        // RFC5952 4.2.2
+        // The symbol "::" MUST NOT be used to shorten just one
+        // 16-bit 0 field.
+        if ((substr_count($compressed, ':') == 7) &&
+            (strpos($compressed, '::') !== false)) {
+            $compressed = str_replace('::', ':0:', $compressed);
+        }
+        return $compressed;
+    }
+
+    // }}}
     // {{{ isCompressible()
 
     /**

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

[2011-07-26 13:55:17] koyama

Description:
------------
The new RFC5952, has established a recommended text representation of
IPv6 address. The compress () output will conform to it almost a little
different.

In RFC5952 4.2.2, "The symbol "::" MUST NOT be used to shorten just one
16-bit 0 field." I wrote new method for it.

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


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=18687&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.