Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

many phpdoc fixes, prepared for new release, added myself to package.xml

git-svn-id: http://svn.php.net/repository/pear/packages/Net_IPv4/trunk@201577 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit e188db2e247dc948c0608c021032c61df48c194e 1 parent 8a9a978
@winks winks authored
Showing with 99 additions and 28 deletions.
  1. +93 −28 IPv4.php
  2. +6 −0 package.xml
View
121 IPv4.php
@@ -1,29 +1,36 @@
<?php
-//
-// +----------------------------------------------------------------------+
-// | PHP Version 4 |
-// +----------------------------------------------------------------------+
-// | 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: Eric Kilfoil <eric@ypass.net> |
-// +----------------------------------------------------------------------+
-//
+/**
+* Class to provide IPv4 calculations
+*
+* PHP versions 4 and 5
+*
+* LICENSE: This source file is subject to version 3.01 of the PHP license
+* that is available through the world-wide-web at the following URI:
+* http://www.php.net/license/3_01.txt. If you did not receive a copy of
+* the PHP License and are unable to obtain it through the web, please
+* send a note to license@php.net so we can mail you a copy immediately.
+*
+* @category Net
+* @package Net_IPv4
+* @author Eric Kilfoil <edk@ypass.net>
+* @author Marco Kaiser <bate@php.net>
+* @author Florian Anderiasch <fa@php.net>
+* @copyright 1997-2005 The PHP Group
+* @license http://www.php.net/license/3_01.txt PHP License 3.01
+* @version CVS: $Id$
+* @link http://pear.php.net/package/Net_IPv4
+*/
-require_once("PEAR.php");
+require_once 'PEAR.php';
+// {{{ GLOBALS
/**
* Map of bitmasks to subnets
*
* This array contains every valid netmask. The index of the dot quad
* netmask value is the corresponding CIDR notation (bitmask).
+ *
+ * @global array $GLOBALS['Net_IPv4_Netmask_Map']
*/
$GLOBALS['Net_IPv4_Netmask_Map'] = array(
0 => "0.0.0.0",
@@ -60,7 +67,8 @@
31 => "255.255.255.254",
32 => "255.255.255.255"
);
-
+// }}}
+// {{{ Net_IPv4
/**
* Class to provide IPv4 calculations
@@ -68,19 +76,29 @@
* Provides methods for validating IP addresses, calculating netmasks,
* broadcast addresses, network addresses, conversion routines, etc.
*
-* @author Eric Kilfoil <edk@ypass.net>
-* @package Net_IPv4
-* @version 1.0
+* @category Net
+* @package Net_IPv4
+* @author Eric Kilfoil <edk@ypass.net>
+* @author Marco Kaiser <bate@php.net>
+* @author Florian Anderiasch <fa@php.net>
+* @copyright 1997-2005 The PHP Group
+* @license http://www.php.net/license/3_01.txt PHP License 3.01
+* @version CVS: @package_version@
+* @link http://pear.php.net/package/Net_IPv4
* @access public
*/
class Net_IPv4
{
+ // {{{ properties
var $ip = "";
var $bitmask = false;
var $netmask = "";
var $network = "";
var $broadcast = "";
var $long = 0;
+
+ // }}}
+ // {{{ validateIP()
/**
* Validate the syntax of the given IP adress
@@ -102,6 +120,9 @@ function validateIP($ip)
return false;
}
}
+
+ // }}}
+ // {{{ check_ip()
/**
* Validate the syntax of the given IP address (compatibility)
@@ -117,6 +138,9 @@ function check_ip($ip)
return $this->validateIP($ip);
}
+ // }}}
+ // {{{ validateNetmask()
+
/**
* Validate the syntax of a four octet netmask
*
@@ -136,6 +160,9 @@ function validateNetmask($netmask)
return true;
}
+ // }}}
+ // {{{ parseAddress()
+
/**
* Parse a formatted IP address
*
@@ -151,7 +178,7 @@ function validateNetmask($netmask)
* The first would be [IP Address]/[BitMask]:
* 192.168.0.0/16
*
- * The second would be [IP Address] [Subnet Mask in quad dot notation]:
+ * The second would be [IP Address] [Subnet Mask in dot quad notation]:
* 192.168.0.0/255.255.0.0
*
* The third would be [IP Address] [Subnet Mask as Hex string]
@@ -222,6 +249,9 @@ function parseAddress($address)
}
}
+ // }}}
+ // {{{ calculate()
+
/**
* Calculates network information based on an IP address and netmask.
*
@@ -274,6 +304,9 @@ function calculate()
return true;
}
+ // }}}
+ // {{{ getNetmask()
+
function getNetmask($length)
{
if (! PEAR::isError($ipobj = Net_IPv4::parseAddress("0.0.0.0/" . $length))) {
@@ -283,6 +316,9 @@ function getNetmask($length)
}
return false;
}
+
+ // }}}
+ // {{{ getNetLength()
function getNetLength($netmask)
{
@@ -294,6 +330,9 @@ function getNetLength($netmask)
return false;
}
+ // }}}
+ // {{{ getSubnet()
+
function getSubnet($ip, $netmask)
{
if (! PEAR::isError($ipobj = Net_IPv4::parseAddress($ip . "/" . $netmask))) {
@@ -304,6 +343,9 @@ function getSubnet($ip, $netmask)
return false;
}
+ // }}}
+ // {{{ inSameSubnet()
+
function inSameSubnet($ip1, $ip2)
{
if (! is_object($ip1) || strcasecmp(get_class($ip1), 'net_ipv4') <> 0) {
@@ -324,9 +366,14 @@ function inSameSubnet($ip1, $ip2)
}
return false;
}
+
+ // }}}
+ // {{{ atoh()
/**
- * Converts a dot-quad formmated IP address into a hexadecimal string
+ * Converts a dot-quad formatted IP address into a hexadecimal string
+ * @param string $addr IP-adress in dot-quad format
+ * @return mixed false if invalid IP and hexadecimal representation as string if valid
*/
function atoh($addr)
{
@@ -337,8 +384,13 @@ function atoh($addr)
return sprintf("%02x%02x%02x%02x", $ap[0], $ap[1], $ap[2], $ap[3]);
}
+ // }}}
+ // {{{ htoa()
+
/**
* Converts a hexadecimal string into a dot-quad formatted IP address
+ * @param string $addr IP-adress in hexadecimal format
+ * @return mixed false if invalid IP and dot-quad formatted IP as string if valid
*/
function htoa($addr)
{
@@ -349,14 +401,23 @@ function htoa($addr)
}
return false;
}
+
+ // }}}
+ // {{{ ip2double()
+
/**
* Converts an IP address to a PHP double. Better than ip2long because
* a long in PHP is a signed integer.
+ * @param string $ip dot-quad formatted IP adress
+ * @return float IP adress as double - positive value unlike ip2long
*/
function ip2double($ip)
{
return (double)(sprintf("%u", ip2long($ip)));
}
+
+ // }}}
+ // {{{ ipInNetwork()
/**
* Determines whether or not the supplied IP is within the supplied network.
@@ -366,9 +427,9 @@ function ip2double($ip)
* network ($network) may be either a string containing a CIDR
* formatted network definition, or a Net_IPv4 object.
*
- * @param string $ip A quad-dot representation of an IP address
- * @param string $network A string representing the network in CIDR format or a Net_IPv4 object.
- * @return boolean true if the IP address exists within the network
+ * @param string $ip A dot quad representation of an IP address
+ * @param string $network A string representing the network in CIDR format or a Net_IPv4 object.
+ * @return bool true if the IP address exists within the network
*/
function ipInNetwork($ip, $network)
{
@@ -385,9 +446,13 @@ function ipInNetwork($ip, $network)
}
return false;
}
+
+ // }}}
}
+// }}}
+
/*
* vim: sts=4 ts=4 sw=4 cindent fdm=marker
*/
-?>
+?>
View
6 package.xml
@@ -17,6 +17,12 @@
<email>bate@php.net</email>
<role>lead</role>
</maintainer>
+ <maintainer>
+ <user>fa</user>
+ <name>Florian Anderiasch</name>
+ <email>fa@php.net</email>
+ <role>developer</role>
+ </maintainer>
</maintainers>
<release>
<version>1.2</version>
Please sign in to comment.
Something went wrong with that request. Please try again.