|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8856 gethostbyname returns hostname instead of adress
Submitted: 2001-01-23 12:28 UTC Modified: 2001-07-21 21:01 UTC
From: niels at creatype dot nl Assigned:
Status: Closed Package: Network related
PHP Version: 4.0.4pl1 OS: Linux 2.2.17
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
40 + 46 = ?
Subscribe to this entry?

 [2001-01-23 12:28 UTC] niels at creatype dot nl
The gethostbyname doesn't seem to work on some of the systems I use. The problem only occurs on some machines, others work fine. The problem only occurs on 4.0x, but not on 3.0x on the same machine.
All machines use the same build of php4.

For example:
   echo (gethostbyname (""));


The bug? also affects functions like mysql_connect.
I am unable to connect to a sql server unless I replace the hostname with an ip adress.

I've traced the problem back to sockets.c, line 817:
a.s_addr = (int) (*(host_struct->h_addr_list[0]));

If I replace the code above with the equivalent code used in php3 the problem is solved:
memcpy (&a.s_addr, *(host_struct->h_addr_list), sizeof (a.s_addr));

If you need more information please let me know.

Niels Leenheer


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-10 16:12 UTC]
Works for me just fine with latest CVS. Please try the 
latest CVS snapshot from


 [2001-03-10 16:30 UTC]
It sounds like a DNS problem to me. It would be wise if you check that out too.
 [2001-03-10 17:13 UTC] niels at creatype dot nl
>It sounds like a DNS problem to me. 
>It would be wise if you check that out too.

I though about this too at first, but the right information is in both cases stored in the host_struct->h_addr_list.
But the information is only correct if you memcpy it to a.s_addr, instead of typecasting it.

 [2001-03-10 20:21 UTC]
For at least some months, gethostbyname() in sockets.c has
been replaced by gethostbyname() in ext/standard/dns.c
which does

memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));

Could you try the latest CVS? Could you test both
gethostbyname() and gethostbynamel() in PHP? They do it
differently. I think both should work.
 [2001-07-21 21:01 UTC]
Works fine for me with the latest version (4.0.6)
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 21 12:03:37 2021 UTC