php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25612 ip2long() and long2ip() results differs.
Submitted: 2003-09-20 02:30 UTC Modified: 2003-09-20 10:47 UTC
From: marrtins at hackers dot lv Assigned:
Status: Not a bug Package: *Network Functions
PHP Version: 4.3.1 OS: Linux 2.4.20
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marrtins at hackers dot lv
New email:
PHP Version: OS:

 

 [2003-09-20 02:30 UTC] marrtins at hackers dot lv
Description:
------------
Should ip address '62.234.229.040' differ from '62.234.229.40' ? I think not. Please check it out!

Reproduce code:
---------------
<?php

printf("%u\n", ip2long('62.234.229.040')); // 1055581472
print long2ip('1055581472')."\n"; // 62.234.229.32
printf("%u\n", ip2long('62.234.229.40')); // 1055581480

?>

Expected result:
----------------
1055581480
62.234.229.32
1055581480


Actual result:
--------------
1055581472
62.234.229.32
1055581480


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-20 07:00 UTC] wez@php.net
040 is octal for 32.
 [2003-09-20 10:47 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Like wez said, prefixing the IP portion with a 0 makes PHP think the number is in octal and not decimal form. This is not unique to PHP, "ping 62.234.229.040" will try to ping 62.234.229.32.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 07:01:25 2019 UTC