php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27710 ip2long() calculates networks (partial ip addr.) wrong
Submitted: 2004-03-26 05:11 UTC Modified: 2004-04-03 08:41 UTC
From: phpbug at labres dot at Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: Linux, FreeBSD
Private report: No CVE-ID: None
 [2004-03-26 05:11 UTC] phpbug at labres dot at
Description:
------------
When given network addresses (partial ip addresses)*),
ip2long() calculates erratic values:

Input        Output           dechex    should be
192          int(192)         c0        c0000000
192.168      int(-1073741656) c00000a8  c0a80000
192.168.1    int(-1062731775) c0a80001  c0a80100

*) you will need this to convert 192/8, 192.168/16 etc
   network addresses.

Reproduce code:
---------------
$net=ip2long("192");
echo dechex($net)."\n";

$net=ip2long("192.168");
echo dechex($net)."\n";

$net=ip2long("192.168.1");
echo dechex($net)."\n";


Expected result:
----------------
c0000000
c0a80000
c0a80100


Actual result:
--------------
c0
c00000a8
c0a80001


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-26 05:21 UTC] phpbug at labres dot at
tested on different OS'es.
 [2004-03-26 09:09 UTC] phpbug at labres dot at
I've now read the documentation of inet_addr(), so this is a feature. Maybe it should be documented.
 [2004-03-26 11:06 UTC] derick@php.net
Yup, it should be.
 [2004-04-03 08:41 UTC] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:12 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=5154d80c091a9dbb5a4930475fa5d869c3face44
Log: fix #27710
 [2020-02-07 07:30 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/base.git;a=commit;h=9113d92830debe853bb85e6d251d8f183d8375df
Log: fix #27710
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 20:01:27 2024 UTC