r39298 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39297‎ | r39298 | r39299 >
Date:16:51, 13 August 2008
Author:aaron
Status:old
Tags:
Comment:
add HexToOct()
Modified paths:
  • /trunk/phase3/includes/IP.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/IP.php
@@ -150,6 +150,24 @@
151151 $ip_oct = preg_replace( '/(^|:)0+' . RE_IPV6_WORD . '/', '$1$2', $ip_oct );
152152 return $ip_oct;
153153 }
 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+ }
154172
155173 /**
156174 * Convert a network specification in IPv6 CIDR notation to an integer network and a number of bits

Status & tagging log