@julienmoumne opened this Issue on April 25th 2011 Member

With my box (PHP 5.3.5, HTTPD 2.2), in _test_P2NinvalidInput

inet_pton('07.07.07.07');

returns

\u0007\u0007\u0007\u0007

instead of expected

\x00\x00\x00\x00

In _testgetHostByAddr, both

Piwik_IP::getHostByAddr('127.0.0.1')
Piwik_IP::getHostByAddr('::1')

return the name of my computer: ju-PC

@robocoder commented on April 25th 2011 Contributor

Is that on Windows?

@julienmoumne commented on April 25th 2011 Member

I should have mentioned it, it's on Windows 7 x64

@mattab commented on April 26th 2011 Member

On Windows XP 32bits, I get many errors:|

Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_P2N -> 255.255.255.255 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 120]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_P2N -> ::ffff:127.0.0.1 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 120]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_P2N_invalidInput -> 07.07.07.07 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 148]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_N2P -> ::ffff:127.0.0.1 vs::ffff:7f00:1 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 182]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_N2P -> 2001:5c0:1000:b::90f8 vs2001:5c0:1000:0b::90f8 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 182]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_prettyPrint -> ::ffff:127.0.0.1 vs::ffff:7f00:1 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 198]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_prettyPrint -> 2001:5c0:1000:b::90f8 vs2001:5c0:1000:0b::90f8 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 198]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_getIpsForRange -> ::ffff:127.0.0.1/120 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 288]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> ::ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 384]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> ::ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 390]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> 0000:0000:0000:0000:0000:ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 384]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_isIpInRange -> 0000:0000:0000:0000:0000:ffff:c0a8:010a in ::ffff:192.168.1.10 at [D:\piwik\svn\trunk\tests\core\IP.test.php line 390]
Fail: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_getHostByAddr -> ::1 -> ip6-localhost at [D:\piwik\svn\trunk\tests\core\IP.test.php line 497]
Exception: D:\piwik\svn\trunk/tests/core/IP.test.php -> Test_Piwik_IP -> test_getHostByAddr -> Unexpected PHP error [gethostbyaddr() [<a href='function.gethostbyaddr'>function.gethostbyaddr</a>]: Address is not in a.b.c.d form] severity [E_WARNING] in [D:\piwik\svn\trunk\core\IP.php line 384]

Good that we have unit tests to find these out ;)

@robocoder commented on April 26th 2011 Contributor

Matt: is that php 5.2.6? (just making sure because pre-5.3 uses the compat functions).

@mattab commented on April 26th 2011 Member

Yes I am running 5.2.6 - if it's too difficult / not possible to have ipv6 on pre 5.3, I think it's reasonnable, but we need to clarify it and fail gracefully (not sure what it would mean?)

@mattab commented on April 26th 2011 Member

When I generate a new visit on windows 5.2.6, with debug on, I see in the piwik.php output:

 New Visit (IP = 0.0.0.0) ```

then below I see

'location_ip' => '' . "\0" . '' . "\0" . '', ```

quite interesting ;)

@robocoder commented on April 26th 2011 Contributor

thanks. i will fix this today.

@robocoder commented on April 26th 2011 Contributor

(In [4564]) fixes #2359 - note: on Windows with php 5.1.x/5.2.x, gethostbyaddr() doesn't work with ipv6 addresses

@mattab commented on April 26th 2011 Member

Thanks for fixing tests. There is still an issue, that on pre 5.3, ipv4 is not supported anymore. Is it possible that we leave the ipv4 address as is somehow?

for example, I try:


Index: piwik.php
===================================================================
--- piwik.php   (revision 4564)
+++ piwik.php   (working copy)
@@ -8,9 +8,10 @@
  *
  * <a class='mention' href='https://github.com/package'>@package</a> Piwik
  */
-$GLOBALS['PIWIK_TRACKER_DEBUG'] = false;
+$GLOBALS['PIWIK_TRACKER_DEBUG'] = !false;
 $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false;
 define('PIWIK_ENABLE_TRACKING', true);
+$_SERVER['REMOTE_ADDR'] = '201.29.95.170';

 if(file_exists('bootstrap.php'))
 {

And, this shows in output: New Visit (IP = 0.0.0.0)

Is it possible, that ipv4 IPs are compatible with new code, so as to not introduce regression?

@robocoder commented on April 26th 2011 Contributor

(In [4565]) fixes #2359 - looks like this debug statement was added while I was working in my own branch

@robocoder commented on April 26th 2011 Contributor

re: comment:10 -- I did a grep and didn't find any other lingering long2ip/ip2long calls that shouldn't be there.

@robocoder commented on April 26th 2011 Contributor

(In [4566]) refs #2359 - catch more edge cases as errors

@robocoder commented on April 27th 2011 Contributor

(In [4567]) refs #2359 - relax some of the rules for compatibility with native function

@robocoder commented on April 27th 2011 Contributor

(In [4570]) refs #2359 - clean up php_compat_inet_pton

@julienmoumne commented on May 1st 2011 Member

I have two minor failing tests in test_getHostByAddr().

<a class='mention' href='https://github.com/php_uname'>@php_uname</a>('n')

returns the name of my machine with capital letters :

JU-PC

instead of what's displayed if I press Windows + Pause :

ju-PC

However,

Piwik_IP::getHostByAddr('127.0.0.1')

correctly returns

ju-PC

failing both asserts.

@robocoder commented on May 1st 2011 Contributor

(In [4621]) refs #2359 - thanks Julien

This Issue was closed on May 1st 2011
Powered by GitHub Issue Mirror