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

From: Date: Fri, 26 Mar 2004 14:09:11 +0000
Subject: #27710 [Opn]: ip2long() calculates networks (partial ip addr.) wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56871@lists.php.net to get a copy of this message
ID: 27710 User updated by: phpbug at labres dot at Reported By: phpbug at labres dot at Status: Open Bug Type: Math related Operating System: Linux, FreeBSD PHP Version: 4.3.4 New Comment: I've now read the documentation of inet_addr(), so this is a feature. Maybe it should be documented. Previous Comments: ------------------------------------------------------------------------ [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.bugs (#56871) next »