[TYPO3-core] RFC: Bug 331: Support IPv6 addresses
Franz Holzinger
franz at fholzinger.com
Wed Mar 8 08:19:28 CET 2006
Hello Bernhard,
>Franz Holzinger wrote:
>
>
>
>>This would be fine with me. Inform me via email when I can replace this
>>function.
>>
>>
>
>
>The simple outcome is: "::" must only be used once. Else the IPv6 addr isn't distinguisuable
>(unique). Read that in the docs - it's written everywhere.
>
>
It's not so easy to find with Google because you have 100 000 matches.
http://www.tldp.org/HOWTO/Linux+IPv6-HOWTO/x439.html
>on any error a '' string is returned.
>
>
>
You have changed interface of the original function and allow a wildcard.
>I do comparison and masking by using boolean arithmetic. just simple shifts and bit-wise &'s.
>
>I also changed cmpIPv4 to this style ... I tought it would be much faster but only about
>2%. does that count :?
>
>
>
>
I do not understand why your version of the validIPv6Addr function
should be faster to put the ip into an array and call the regexp in a
loop. Here you did not use bit shifts or bitwise '&'.
Greets,
Franz
>+
>+ function validIPv6Addr($testIP, $allowWildcard = false) {
>+ $testParts = t3lib_div::trimExplode('::', $testIP);
>+ if (count($testParts)>2) {
>+ return '';
>+ }
>+ $p1 = t3lib_div::trimExplode(':', $testParts[0], 1);
>+ $p2 = t3lib_div::trimExplode(':', $testParts[1], 1);
>+ if (($set = count($p1)+count($p2))>8) {
>+ return '';
>+ }
>+ if (!isset($testParts[1])&&count($p1)!=8) {
>+ return '';
>+ }
>+ if ($set<8) {
>+ $pfill = array_fill(0, 8-$set, 0);
>+ } else {
>+ $pfill = array();
>+ }
>+ $testParts = array_merge($p1, $pfill, $p2);
>+ foreach ($testParts as $idx => $v) {
>+ $v = strtolower($v);
>+ if ($allowWildcard && trim($v)=='*') {
>+ $testParts[$idx] = '*';
>+ } elseif (!preg_match('/[0-9a-fA-F]{1,4}/', $v)) {
>+ return '';
>+ } else {
>+ $testParts[$idx] = str_pad($v, 4, '0', STR_PAD_LEFT);
>+ }
>+ }
>+ return implode(':', $testParts);
>+ }
>+
>
>
More information about the TYPO3-team-core
mailing list