Browse files

Added the ipInNetwork method and the updated the package.xml refelecting

the change.


git-svn-id: http://svn.php.net/repository/pear/packages/Net_IPv4/trunk@133474 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 9d80381 commit 5f958ff62e1a25363e4353a10f20be98565fba95 Eric Kilfoil committed Jun 28, 2003
Showing with 60 additions and 3 deletions.
  1. +31 −0 IPv4.php
  2. +29 −3 package.xml
View
31 IPv4.php
@@ -308,6 +308,37 @@ function ip2double($ip)
{
return((double)(sprintf("%u", ip2long($ip))));
}
+
+ /**
+ * Determines whether or not the supplied IP is within the supplied network.
+ *
+ * This function determines whether an IP address is within a network.
+ * The IP address ($ip) must be supplied in dot-quad format, and the
+ * 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
+ */
+ function ipInNetwork($ip, $network)
+ {
+ if (! is_object($network) || get_class($network) != 'net_ipv4') {
+ $network = Net_IPv4::parseAddress($network);
+ }
+ if (! is_object($network) || get_class($network) != 'net_ipv4') {
+ return($network);
+ }
+ $net = Net_IPv4::ip2double($network->network);
+ $bcast = Net_IPv4::ip2double($network->broadcast);
+ $ip = Net_IPv4::ip2double($ip);
+ unset($network);
+ if ($ip >= $net && $ip <= $bcast) {
+ return(TRUE);
+ }
+ return(FALSE);
+ return((double)(sprintf("%u", ip2long($ip))));
+ }
}
?>
View
32 package.xml
@@ -19,15 +19,41 @@
</maintainer>
</maintainers>
<release>
- <version>1.0</version>
- <date>2002-08-20</date>
+ <version>1.2</version>
+ <date>Unknown</date>
<license>PHP 2.0</license>
<state>stable</state>
- <notes>Initial Release</notes>
+ <notes>Added ipInNetwork method.</notes>
<filelist>
<dir name="/" baseinstalldir="Net">
<file role="php">IPv4.php</file>
</dir>
</filelist>
</release>
+ <changelog>
+ <release>
+ <version>1.1</version>
+ <date>2003-06-22</date>
+ <license>PHP 2.0</license>
+ <state>stable</state>
+ <notes>Created an ip2double method as a workaround for PHP long ints being unsigned</notes>
+ <filelist>
+ <dir name="/" baseinstalldir="Net">
+ <file role="php">IPv4.php</file>
+ </dir>
+ </filelist>
+ </release>
+ <release>
+ <version>1.0</version>
+ <date>2002-08-20</date>
+ <license>PHP 2.0</license>
+ <state>stable</state>
+ <notes>Initial Release</notes>
+ <filelist>
+ <dir name="/" baseinstalldir="Net">
+ <file role="php">IPv4.php</file>
+ </dir>
+ </filelist>
+ </release>
+ </changelog>
</package>

0 comments on commit 5f958ff

Please sign in to comment.