|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55472 ip2long(integer) returns integer
Submitted: 2011-08-21 03:09 UTC Modified: 2015-07-23 23:37 UTC
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: php at linuxhosted dot ca Assigned: cmb (profile)
Status: Closed Package: *Network Functions
PHP Version: 5.3.7 OS: Windows
Private report: No CVE-ID: None
 [2011-08-21 03:09 UTC] php at linuxhosted dot ca
On windows, the ip2long function does not return false on an invalid input, on other operating systems it properly returns false.

Test script:

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-21 10:10 UTC]
-Type: Bug +Type: Documentation Problem
 [2011-08-21 10:10 UTC]
in the OS without inet_ntop, php ip2long use inet_addr handle the conversion, 
obviously there are difference between these two function when meet a not well-
format numbers-and-dots notation.

maybe the document should be more clearly to explain the difference?
 [2011-08-21 10:19 UTC]
-Status: Open +Status: Analyzed
 [2011-08-22 13:55 UTC]
-Status: Analyzed +Status: Assigned -Assigned To: +Assigned To: laruence
 [2011-08-22 13:55 UTC]
(Ignore the assigned status laruence, just to notify you)

We do have inet_ntop() + inet_pton() on Windows, see win32/inet.c which we implemented in 5.3 so if thats the case that we fall back to inet_addr() on Windows its a bug as they are natively implemented.

After it might be worth setting this bug to "To be documented" so the behaviour can indeed be noted if not already in the manual.
 [2011-08-23 15:10 UTC] php at linuxhosted dot ca
-Type: Documentation Problem +Type: Bug
 [2011-08-23 15:10 UTC] php at linuxhosted dot ca
As kalle has said, this is not a documentation bug. The inet_ntop() and inet_pton() functions have existed on Windows since 5.3
 [2011-08-23 15:25 UTC]
-Type: Bug +Type: Documentation Problem -Assigned To: laruence +Assigned To:
 [2011-08-23 16:09 UTC] php at linuxhosted dot ca
-Type: Documentation Problem +Type: Bug
 [2011-08-23 16:09 UTC] php at linuxhosted dot ca
pajoye, this is not a documentation bug
 [2011-08-23 16:16 UTC]
-Assigned To: +Assigned To: pajoye
 [2011-08-23 16:16 UTC]
It is as it can be considered as valid IP and it is what happens on Windows, using 
the underlying equivalent API.

That being said, I will double check again with the inent team at msft to be sure 
that there is no bug in the API itself.

assigned to me.
 [2011-08-23 16:28 UTC] php at linuxhosted dot ca
As we've been saying, the fact that this function uses a Windows specific api is the bug. It should be using inet_ntop/pton like every other OS does. Also, you say that "26" is a valid IP, which is totally wrong, the function considers 26 to be "", when if it was taking it as a valid ip, it would mean that its ", take for example, long2ip(ip2long("10.200")); this becomes, instead of what it should be,

Also, it makes no sense for a function that is not OS specific to have different results on different platforms, PHP is supposed to be multi-platform, so except for functions that are meant to be platform specific , functions shouldn't be giving a totally different result on different platforms, it just makes no sense.
 [2011-08-23 16:31 UTC]
There is no such function in Windows below Vista or Windows 7. So no, there is no 
bug here but maybe in the WSAStringToAddress function.
 [2011-08-23 16:49 UTC] php at linuxhosted dot ca
Maybe you better take another look, and another read through the comments.

PHP 5.3 implemented these functions on windows:
look in win32/inet.c
 [2011-08-23 17:14 UTC]
I implemented them and I perfectly know how it is done and what they do, thanks.
 [2015-07-23 23:37 UTC]
-Status: Assigned +Status: Closed -Assigned To: pajoye +Assigned To: cmb
 [2015-07-23 23:37 UTC]
This issue has already been resolved as of PHP 5.5.0. Now the
documentation (changelog) has been updated, and a regression test
has been added.

Thank you for the report, and for helping us to make PHP better.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 11:01:25 2019 UTC