Source for file IPv6.php
Documentation is available at IPv6.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Alexander Merz <alexander.merz@web.de> |
// +----------------------------------------------------------------------+
// $Id: IPv6.php,v 1.9 2005/02/13 13:04:51 alexmerz Exp $
* Class to validate and to work with IPv6
* Todo: some optimizations for checkIPv6()
* @author Alexander Merz <alexander.merz@t-online.de>
* @version $Id: IPv6.php,v 1.9 2005/02/13 13:04:51 alexmerz Exp $
* Uncompresses an IPv6 adress
* RFC 2373 allows you to compress zeros in an adress to '::'. This
* function expects an valid IPv6 adress and expands the '::' to
* Example: FF01::101 -> FF01:0:0:0:0:0:0:101
* @param string $ip a valid IPv6-adress (hex format)
* @return string the uncompressed IPv6-adress (hex format)
if (false !== strpos($ip, '::') ) {
list ($ip1, $ip2) = explode('::', $ip);
if(-1 == $c1 && -1 == $c2) { // ::
$uip = "0:0:0:0:0:0:0:0";
} else if(-1== $c1) { // ::xxx
} else if(-1== $c2) { // xxx::
* Compresses an IPv6 adress
* RFC 2373 allows you to compress zeros in an adress to '::'. This
* function expects an valid IPv6 adress and compresses successive zeros
* Example: FF01:0:0:0:0:0:0:101 -> FF01::101
* @param string $ip a valid IPv6-adress (hex format)
* @return string the compressed IPv6-adress (hex format)
for($i=0; $i< count($ipp); $i++ ) {
$pos = strpos($cip, $pattern);
$pattern = $pattern. ":0";
* Splits an IPv6 adress into the IPv6 and a possible IPv4 part
* RFC 2373 allows you to note the last two parts of an IPv6 adress as
* an IPv4 compatible adress
* Example: 0:0:0:0:0:0:13.1.68.3
* 0:0:0:0:0:FFFF:129.144.52.38
* @param string $ip a valid IPv6-adress (hex format)
* @return array [0] contains the IPv6 part, [1] the IPv4 part (hex format)
* Checks if the given IP is IPv6-compatible
* @param string $ip a valid IPv6-adress
* @return boolean true if $ip is an IPv6 adress
if (!empty ($ipPart[0 ])) {
for ($i = 0; $i < count($ipv6); $i++ ) {
} elseif (6 == $count and !empty ($ipPart[1 ])) {
for ($i = 0; $i < count($ipv4); $i++ ) {
if ($ipv4[$i] >= 0 && (integer) $ipv4[$i] <= 255 && preg_match("/^\d{1,3}$/", $ipv4[$i])) {
Documentation generated on Mon, 11 Mar 2019 14:23:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|