php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #33170 IPv6: gethostbyname() fails on resolving IPv6 hostnames
Submitted: 2005-05-28 13:25 UTC Modified: 2009-04-21 00:54 UTC
From: web at vollbrecht dot net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.10 OS: Linux 2.6.10-1
Private report: No CVE-ID: None
 [2005-05-28 13:25 UTC] web at vollbrecht dot net
Description:
------------
perhaps related to #12678.

gethostbyname() gives the IPv6 hostname back instead if the IPv6 ip. In IPv4 everything works fine.

Note: IPs and hostnames in the following snipplets are replaced with example entries. It was tested with working IPs both in IPv4 and IPv6.

Reproduce code:
---------------
$client_ip = $_SERVER["REMOTE_ADDR"];
$client_hostname = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
$client_hostname2ip = gethostbyname(gethostbyaddr($_SERVER["REMOTE_ADDR"]));

echo $client_ip."->".$client_hostname."->".$client_hostname2ip;

Expected result:
----------------
In IPv4:
10.11.12.13->server.domain.de->10.11.12.13 

In IPv6:
3ffe:1::1->server.ipv6.domain.de->3ffe:1::1

Actual result:
--------------
In IPv4 (working fine): 10.11.12.13->server.domain.de->10.11.12.13 

In IPv6 (last output broken): 3ffe:1::1->server.ipv6.domain.de->server.ipv6.domain.de

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-28 20:16 UTC] wez@php.net
gethostbyname() is an IPv4 only function.
inet_pton and inet_ntop are possible alternatives that are available in PHP 5.

 [2009-04-21 00:54 UTC] joey@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

gethostbyname and gethostbynamel are now documented as giving the "IPv4
address"
 [2013-09-04 08:32 UTC] daverandom@php.net
Automatic comment from SVN on behalf of daverandom
Revision: http://svn.php.net/viewvc/?view=revision&revision=331286
Log: Typo fix in MySQLi quick start

---
Provided by Anonymous #33170
 [2017-04-18 13:44 UTC] epgvozdet at gmail dot com
Still not working properly:

Reproduce code:
---------------
$ip6 = "2620:0:860:ed1a::1";
$client_hostname = gethostbyaddr($ip6);
$client_hostname2ip = gethostbyname(gethostbyaddr($ip6));

echo $ip6."->".$client_hostname."->".$client_hostname2ip;

Expected result:
----------------
2620:0:860:ed1a::1->text-lb.codfw.wikimedia.org->2620:0:860:ed1a::1

Actual result:
--------------
2620:0:860:ed1a::1->text-lb.codfw.wikimedia.org->208.80.153.224
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC