Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > BUG: sprintf(%u) and ip2long
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 2nd July 19:02
daevid
External User
 
Posts: 1
Default BUG: sprintf(%u) and ip2long



Could be my not understanding of something, but I think there is a bug in
using ip2long() and sprintf(%u) as indicated on this page:
http://us4.php.net/manual/en/function.ip2long.php

Look at the example below:

//this conversion seems broken
// $startIP_long = sprintf("%u",ip2long($QRange1));
// $endIP_long = sprintf("%u",ip2long($QRange2));

$startIP_long = ip2long($QRange1);
$endIP_long = ip2long($QRange2);

echo "QRange1 = ".$QRange1." and QRange2 = ".$QRange2."<BR>";
echo "startIP_long = ".$startIP_long." and endIP_long =
".$endIP_long."<BR>";
echo "startIP_long = ".long2ip($startIP_long)." and endIP_long =
".long2ip($endIP_long)."<BR>";


The first //commented block will give:

QRange1 = 192.169.12.40 and QRange2 = 192.169.20.40
startIP_long = 3232304168 and endIP_long = 3232306216
startIP_long = 127.255.255.255 and endIP_long = 127.255.255.255

(wtf did the "127.255.255.255" come from?!)

While the second works properly...

QRange1 = 192.169.12.40 and QRange2 = 192.169.20.40
startIP_long = -1062663128 and endIP_long = -1062661080
startIP_long = 192.169.12.40 and endIP_long = 192.169.20.40
  Reply With Quote


 


2 2nd July 19:03
php-general
External User
 
Posts: 1
Default BUG: sprintf(%u) and ip2long



What version of php? It works find in 4.3.3.

echo long2ip(3232304168);
---
192.169.12.40

Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
  Reply With Quote
3 2nd July 19:03
daevid
External User
 
Posts: 1
Default BUG: sprintf(%u) and ip2long


Good point...

v4.1.2, Linux stripples.devel.redhat.com 2.4.18-11smp #1 SMP Thu Aug 15
06:41:59 EDT 2002 i686 unknown
This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.1.1, Copyright (c) 1998-2001 Zend Technologies
with Zend Optimizer v2.1.0, Copyright (c) 1998-2003, by Zend
Technologies
Apache/1.3.22

Also, if you notice, in my example, the problem was using the sprintf (%u)
as per the example on the php website. Just doing like you did works for me
too...
  Reply With Quote


 


4 2nd July 19:03
php-general
External User
 
Posts: 1
Default BUG: sprintf(%u) and ip2long


still works using sprintf() with 4.3.3
http://zirzow.dyndns.org/html/php/te...ng/ip2long.php


Curt
--
"My PHP key is worn out"

PHP List stats since 1997:
http://zirzow.dyndns.org/html/mlists/
  Reply With Quote
Reply


Thread Tools
Display Modes




666