php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8217 long2ip gives 127.255.255.255 result instead of correct value
Submitted: 2000-12-12 18:43 UTC Modified: 2003-01-18 10:27 UTC
From: christoph at lameter dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.3pl1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: christoph at lameter dot com
New email:
PHP Version: OS:

 

 [2000-12-12 18:43 UTC] christoph at lameter dot com
Feed the following list to this script and you will see how long2ip screws up. There is an overflow condition it seems:

178519801
1061963075
1070665698
1070668067
2180645450
2180645574
2180645666
2180645722
2180647266
2180648705
2180649062
2180652350
2180676205
2301042637
2554268534
2554278550
2554279006
3232238083
3232238334
3435825182
3435825736
3475085569
3506496261
3508072161
3522432302
3528459286
3528470646
3528471070


<?php

function lng2ip($ip) {
   settype($ip,"double");
   return floor($ip/(256*256*256)) . "." . floor($ip/(256*256))%256 . "." . floor($ip/256)%256 . "." .
}

$fh=fopen("xx","r");
while ($x=fgets($fh,100)) {
  $x=rtrim ($x);
  echo "$x ".long2ip($x)." ".lng2ip($x)."\n";
}

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-13 06:35 UTC] stas@php.net
Numbers you brought are not valid PHP longs, they don't fit
signed long. So they don't give good result in long2ip. It
might be done with a special hack, but it's not a bug - it's
a lacking feature.
 [2003-01-18 10:27 UTC] moriyoshi@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon May 25 08:00:02 2026 UTC