Index: trunk/phase3/includes/IP.php |
— | — | @@ -150,6 +150,24 @@ |
151 | 151 | $ip_oct = preg_replace( '/(^|:)0+' . RE_IPV6_WORD . '/', '$1$2', $ip_oct ); |
152 | 152 | return $ip_oct; |
153 | 153 | } |
| 154 | + |
| 155 | + /** |
| 156 | + * Given an unsigned integer, returns an IPv6 address in octet notation |
| 157 | + * @param $ip integer IP address. |
| 158 | + * @return string |
| 159 | + */ |
| 160 | + public static function HextoOctet( $ip_hex ) { |
| 161 | + // Convert to padded uppercase hex |
| 162 | + $ip_hex = str_pad( strtoupper($ip_hex), 32, '0'); |
| 163 | + // Seperate into 8 octets |
| 164 | + $ip_oct = substr( $ip_hex, 0, 4 ); |
| 165 | + for ($n=1; $n < 8; $n++) { |
| 166 | + $ip_oct .= ':' . substr($ip_hex, 4*$n, 4); |
| 167 | + } |
| 168 | + // NO leading zeroes |
| 169 | + $ip_oct = preg_replace( '/(^|:)0+' . RE_IPV6_WORD . '/', '$1$2', $ip_oct ); |
| 170 | + return $ip_oct; |
| 171 | + } |
154 | 172 | |
155 | 173 | /** |
156 | 174 | * Convert a network specification in IPv6 CIDR notation to an integer network and a number of bits |