From 3597b6f649333be6d0f44d4344d8c05341c006fb Mon Sep 17 00:00:00 2001 From: Jason Morriss Date: Mon, 5 May 2014 08:58:15 -0400 Subject: [PATCH] Added getTrueCidr() method --- src/Lifo/IP/CIDR.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Lifo/IP/CIDR.php b/src/Lifo/IP/CIDR.php index c91a10a..5ed92f9 100644 --- a/src/Lifo/IP/CIDR.php +++ b/src/Lifo/IP/CIDR.php @@ -254,13 +254,31 @@ public function isIPv6() * and the starting IP is not on a valid network boundrary (eg: Displaying * an IP from an interface). * - * @return string IP in CIDR notation "ipaddr/prefix" + * Note: The CIDR block returned is NOT always bit aligned. + * + * @return string IP in CIDR notation "start_ip/prefix" */ public function getCidr() { return $this->start . '/' . $this->prefix; } + /** + * Get the TRUE cidr notation for the subnet block. + * + * This is useful for when you want a string representation of the IP/prefix + * and the starting IP is not on a valid network boundrary (eg: Displaying + * an IP from an interface). + * + * Note: The CIDR block returned is ALWAYS bit aligned. + * + * @return string IP in CIDR notation "network/prefix" + */ + public function getTrueCidr() + { + return $this->getNetwork() . '/' . $this->prefix; + } + /** * Get the [low,high] range of the CIDR block *