Bug #13443 Updated: gethostbyname returns the name not the IP addr.
| From: | brooks at netgate dot net | Date: | Thu, 27 Sep 2001 16:45:03 +0000 |
| Subject: | Bug #13443 Updated: gethostbyname returns the name not the IP addr. | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-66738@lists.php.net to get a copy of this message | ||
ID: 13443
User updated by: brooks@netgate.net
Reported By: brooks@netgate.net
Status: Duplicate
Bug Type: Unknown/Other Function
Operating System: BSDI 4.1
PHP Version: 4.0.6
New Comment:
I'm with you... The program below works fine, as does dig, nslookup, perl, etc. So, I'm
at a loss as to why PHP doesn't work. I sent an email to the BSDI users list and everyone is
convinced that you MUST run a local named server for PHP to work correctly. This makes no sense (to
me).
vp3: {4} % ldd ../cgi-bin/php
libdl.so => /shlib/libdl.so (0x48169000)
libm.so => /shlib/libm.so.0.0 (0x4816d000)
libgcc.so.1 => /shlib/libgcc.so.1 (0x4817f000)
libc.so.1 => /shlib/libc.so.1 (0x4818b000)
vp3: {5} % ldd gethostbyname
libgcc.so.1 => /shlib/libgcc.so.1 (0x48052000)
libc.so.1 => /shlib/libc.so.1 (0x4805e000)
Previous Comments:
------------------------------------------------------------------------
[2001-09-27 02:22:02] venaas@php.net
PHP uses the resolver library(ies) installed on your
system, just as the other software installed. It is
possible that you have several libraries and nslookup
uses something else though. If you have nsswitch.conf
or similar you should make sure that is okay, but if
for instance ping hostname works (where hostname is
not in /etc/hosts or NIS...), it should be okay.
Please check that resolv.conf is readable for all. You
aren't running PHP in chroot environment, are you?
------------------------------------------------------------------------
[2001-09-26 17:43:08] jimw@php.net
php does not require a local dns server to be running unless your system's C library
gethostbyname() call does (which seems extraordinarily unlikely).
here's a small c program you can use to test your system's gethostbyname(). if it says
that no ip address is found, that's the exact same situation in which php's
gethostbyname() will return the original hostname.
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char **argv) {
struct hostent *host;
struct in_addr in;
if (argc != 2) {
fprintf(stderr,"usage: %s hostname\n", argv[0]);
exit(1);
}
host = gethostbyname(argv[1]);
if (host->h_length) {
memcpy(&in.s_addr, *(host->h_addr_list), sizeof(in.s_addr));
fprintf(stderr,"%s\n",inet_ntoa(in));
}
else {
fprintf(stderr,"no ip address found for %s\n", argv[1]);
exit(1);
}
exit(0);
}
------------------------------------------------------------------------
[2001-09-26 17:33:02] brooks@netgate.net
Does PHP require a local bind running? Everything seems to point in that direction. The resolver
libs are doing a lookup to the address of 0.0.0.0 vs. the servers as configured in resolv.conf.
;; Querying server (# 1) address = 0.0.0.0
------------------------------------------------------------------------
[2001-09-25 17:16:30] brooks@netgate.net
IMHO this is not the same as #13423, which is why I didn't list it in the original report.
Although the data returned is the same (hostname instead of IP address) the reason for the failure
is seems very different.
------------------------------------------------------------------------
[2001-09-25 16:45:51] jimw@php.net
duplicate of 13423, among the others listed in the report. gethostbyname() returns the hostname it
is passed when the C-level gethostbyname() call fails.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/?id=13443
Edit this bug report at http://bugs.php.net/?id=13443&edit=1