Bug #10924 Updated: long2ip gives wrong result/binary arithmatic does not work
| From: | sterling@php.net | Date: | Fri, 07 Dec 2001 13:33:41 +0000 |
| Subject: | Bug #10924 Updated: long2ip gives wrong result/binary arithmatic does not work | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-72846@lists.php.net to get a copy of this message | ||
ID: 10924
Updated by: sterling
Reported By: richarde@eskom.co.za
Old Status: Suspended
Status: Closed
Bug Type: Network related
Operating System: Linux Redhat 6.2
PHP Version: 4.0.4pl1
New Comment:
long2ip is now fixed as well, as it accepts a string value, which is then properly converted to a
unsigned long...
Previous Comments:
------------------------------------------------------------------------
[2001-05-19 20:43:28] derick@php.net
There is no solution for this, because PHP only deals with signed longs.
However, you can now use the %u modifier in printf and sprintf to show a long unsigned number like
this:
<?php
printf ("%u\n", ip2long ("147.110.52.10"));
?>
2473473034
I suspended this bug, until unsigned longs are really working (there are some feature request for
this already).
Derick
------------------------------------------------------------------------
[2001-05-17 09:24:07] richarde@eskom.co.za
$x = 2473473034; // 147.110.52.10 in int form
settype($x, "integer"); // this line has no effect on final result of long2ip
echo "long ".is_long($x);
echo "<P>";
$y = ip2long("147.110.52.10");
echo "long ".is_long($y);
echo "<P>";
echo ip2long("147.110.52.10"); // should be 2473473034
echo "<P>";
echo long2ip($y); // correct result here
echo "<P>";
echo long2ip($x); // wrong result
echo "<P>";
echo $y & 127; // correct result
echo "<P>";
echo $x & 127; // incorrect result - should be 10
echo "<P>";
**** cut ****
basically there is no way to do ip arithmatic using php - I cannot get large numbers like ip
addresses from a database stored as integers and minipulate them - AND, OR and XOR do not work on
large number as in example.
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=10924&edit=1