|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38197 ip2long() not accepting hex 0xffffffff
Submitted: 2006-07-24 19:08 UTC Modified: 2006-07-25 13:16 UTC
From: gk at gknw dot de Assigned:
Status: Not a bug Package: Network related
PHP Version: 5.1.4 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gk at gknw dot de
New email:
PHP Version: OS:


 [2006-07-24 19:08 UTC] gk at gknw dot de
Although ip2long() works fine with it fails when 0xffffffff is passed in.
Other hex values work fine.
Seems this was introduced with PHP 5.x - PHP 4.x is not affected; there it works as I expect.

Reproduce code:
Nonworking sample on PHP 5.x:
Working same sample on PHP 4.x:
Script for download:

Expected result:
Same result on PHP5 as with PHP4.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-25 07:04 UTC]
0xffffffff is not an IP address and the underlying inet_addr() function doesn't think it's valid too.
 [2006-07-25 12:46 UTC] gk at gknw dot de
I agree that 0xffffffff is not an IP address and the underlying inet_addr() function doesn't think it's valid - but it doesnt think it's valid with either, and to capture that there was code introduced with PHP 5.x.
With only _two_ additional lines of code we could again get the same behaviour as with PHP 4.x:
--- basic_functions.c.orig	Sun Aug 21 20:36:34 2005
+++ basic_functions.c	Tue Jul 25 11:15:32 2006
@@ -1265,7 +1265,9 @@
 		/* the only special case when we should return -1 ourselves,
 		 * because inet_addr() considers it wrong.
-		if (!memcmp(Z_STRVAL_PP(str), "", Z_STRLEN_PP(str))) {
+		if (!memcmp(Z_STRVAL_PP(str), "", Z_STRLEN_PP(str)) ||
+				!memcmp(Z_STRVAL_PP(str), "0xffffffff", Z_STRLEN_PP(str)) ||
+				!memcmp(Z_STRVAL_PP(str), "0xFFFFFFFF", Z_STRLEN_PP(str)) ) {
here's a PHP 5.0.5 running with the patch:
and you can see now again same behaviour as with PHP 4.x:

patch for download here:

 [2006-07-25 12:55 UTC]
Your patch won't work as 0xffffffff is not a string, but float.
Also, I don't really see why do you need the function in this case - just (int)0xffffffff is enough.
And I don't think we're going to support invalid IP addresses in a function which is supposed to accept IP addresses.
 [2006-07-25 13:16 UTC] gk at gknw dot de
sorry, but I cant follow: if I pass in a string "0xffffffff" what should convert it to float? perhaps Z_STRVAL_PP()? Ok, if so then please forgive - I couldnt find Z_STRVAL_PP() documented.
The reason why I need this function is that a couple of routers and switches represent IPs mixed bewteen the hex and the dotted format - and in the past 10 years I used the nice feature that inet_addr() can deal with both dotted and hex formated IPs from C, Perl, and PHP.
Also it wouldnt be support for 'invalid IP addresses' but just for the _one_ special case which fails with dotted format too.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Aug 15 06:05:46 2022 UTC