ID: 16020 Updated by: [EMAIL PROTECTED] Reported By: [EMAIL PROTECTED] -Status: Feedback +Status: Open Bug Type: Unknown/Other Function Operating System: FreeBSD 4.4-STABLE i386 PHP Version: 4.1.2 New Comment:
Strange... you script works fine for me... Previous Comments: ------------------------------------------------------------------------ [2002-03-12 10:41:44] [EMAIL PROTECTED] I've done a little more digging to see why the problem occured. I'm not 100% sure if it is a problem with php, or misuse of php really. However it might be worth adding in something to make this work. My script was getting the decimal address as a string, an integer. The following example should illustrate it. <? $moo = "167772161"; echo long2ip($moo); echo "<BR>"; $moo = 167772161; echo long2ip($moo); ?> As a side thing you also need to add the following to get larger numbers to work when using strings: if ($moo > 0) $moo += pow(2,32); ------------------------------------------------------------------------ [2002-03-12 09:04:56] [EMAIL PROTECTED] Sorry, I missed out a bit: inet4oct blah; ;) ------------------------------------------------------------------------ [2002-03-12 08:58:06] [EMAIL PROTECTED] Can you provide a simple sample script with data that shows the problem? ------------------------------------------------------------------------ [2002-03-12 08:47:38] [EMAIL PROTECTED] I have found some problems where long2ip (and I would presume ip2long by the same token) seems to return an IP address offset by one. I'm not sure if it is the implmentation of inet_ntoa on the platform I am using or something else. Even if this is a problem with a particular version of a library on my machine, maybe it might be worth using a method other than inet_ntoa for ease of platform independance? Perhaps something along there lines.... ? struct inet4addr { unsigned int a:8; unsigned int b:8; unsigned int c:8; unsigned int d:8; }; typedef union { unsigned int inet4dec; struct inet4addr inet4oct; } inet4oct; blah.inet4dec = <SOME LONG IP HERE>; printf("%i.%i.%i.%i\n", blah.inet4oct.a, blah.inet4oct.b,blah.inet4oct.c,blah.inet4oct.d); ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=16020&edit=1