note 83320 added to function.ip2long
| From: | jpmarcotte at gmail dot com | Date: | Tue, 20 May 2008 22:10:33 +0000 |
| Subject: | note 83320 added to function.ip2long | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139564@lists.php.net to get a copy of this message | ||
In using a combination of jbothe's code below and some of the "$mask = 0xFFFFFFFF <<
(32 - $bits)" type code, I ran into an error with some later calculations on a 64 bit machine.
Keep in mind that when you're analyzing numbers meant to be treated as 32 bits wide (such as IP
addresses), you may want to truncate them. Without relying on other libraries, it was simple enough
to follow any calculations that may end with different results on a 64 bit machine with " &
0xFFFFFFFF"
Though in many cases, it seems like it might be simpler to just use "~0 << ..." for
initial shifting to create the network mask instead of "0xFFFFFFFF << ...". I
don't know that it guarantees further operations to work as expected though.
----
Server IP: 209.41.74.194
Probable Submitter: 66.146.193.242
----
Manual Page -- http://www.php.net/manual/en/function.ip2long.php
Edit -- https://master.php.net/note/edit/83320
Del: integrated -- https://master.php.net/note/delete/83320/integrated
Del: useless -- https://master.php.net/note/delete/83320/useless
Del: bad code -- https://master.php.net/note/delete/83320/bad+code
Del: spam -- https://master.php.net/note/delete/83320/spam
Del: non-english -- https://master.php.net/note/delete/83320/non-english
Del: in docs -- https://master.php.net/note/delete/83320/in+docs
Del: other reasons-- https://master.php.net/note/delete/83320
Reject -- https://master.php.net/note/reject/83320
Search -- https://master.php.net/manage/user-notes.php