#27710 [Opn->Csd]: ip2long() calculates networks (partial ip addr.) wrong

From: Date: Sat, 03 Apr 2004 13:41:47 +0000
Subject: #27710 [Opn->Csd]: ip2long() calculates networks (partial ip addr.) wrong
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969359911@lists.php.net to get a copy of this message
ID: 27710 Updated by: nlopess@php.net Reported By: phpbug at labres dot at -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: Linux, FreeBSD PHP Version: 4.3.4 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2004-03-26 11:06:30] derick@php.net Yup, it should be. ------------------------------------------------------------------------ [2004-03-26 09:09:10] 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 05:21:20] phpbug at labres dot at tested on different OS'es. ------------------------------------------------------------------------ [2004-03-26 05:11:48] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27710&edit=1

« previous php.doc (#969359911) next »