From: [EMAIL PROTECTED]
Operating system: Linux
PHP version: 4.0.6
PHP Bug Type: Network related
Bug description: make ip2long and long2ip handle unsigned longs correctly
Actually the my fix for this problem is on the PHP side,
not in the PHP-code it self:
function jk_ip2long ($ip) {
preg_match("#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#",
$ip, $a);
$long =
$a[1] << 24 |
$a[2] << 16 |
$a[3] << 8 |
$a[4] << 0;
## handling negative urls
if($long < 0) $long += pow(2,32);
return $long;
}
## long2ip
function jk_long2ip ($long) {
## handle long value which should be signed in PHP but
are unsigned
if ($long > 0x7fffffff) {
## although this code seems to be useless, it does
what we want
$l = ($long - 0x7fffffff) - 1;
$long = -(0x7fffffff - $l) - 1;
}
$ip3 = sprintf("%d.%d.%d.%d",
$long >> 24 & 0xff,
$long >> 16 & 0xff,
$long >> 8 & 0xff,
$long >> 0 & 0xff
);
return $ip3;
}
You can see a working example at
http://jan.kneschke.de/projects/phpbugs/ip2long.php
--
Edit bug report at: http://bugs.php.net/?id=14018&edit=1
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]