gethostbyaddr not working on Tru64 (including WORKING bugfix)
| From: | Horst G. Reiterer | Date: | Wed, 17 May 2000 11:37:54 +0000 |
| Subject: | gethostbyaddr not working on Tru64 (including WORKING bugfix) | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-15115@lists.php.net to get a copy of this message | ||
Hi,
we recently noticed a bug in the latest PHP4 release running on Tru64 UNIX.
The gethostbyaddr function fails resolving any host in any case.
We know that this is a bug as our environment is perfectly working and other
apps can succesfully resolve any resolvable hosts.
This is not only a bug report but also includes the solution.
In ext/standard/dns.c, gethostbyaddr is called that way:
hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
This fails in any case as we found out by isolating this code into a small
test application.
At the bottom of this mail I attached the man pages on the Tru64 glibc
gethostbyaddr function, hope this helps!
We've rewritten that line and the following WORKS:
hp = gethostbyaddr((char *) &addr, sizeof(struct in_addr), AF_INET);
Why? Well, it is because of the 2nd parameter.
sizeof(addr) returns 8 which is wrong, the corrent return value would have
to be 4 which is correctly returned when using sizeof(struct in_addr).
hope you'll include this fix in the next release of PHP4.
Thanks in advance!
cheers,
Horst G Reiterer
--
gethostbyaddr(3)
gethostbyaddr(3)
NAME
gethostbyaddr, gethostbyaddr_r - Gets a network host entry by address
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <netdb.h>
struct hostent *gethostbyaddr(
const void *addr,
size_t len,
[Tru64 UNIX] The following obsolete routine is supported in order to
main-
tain backward compatibility with previous versions of the operating
system.
You should not use it in new designs.
int *gethostbyaddr_r(
const char *addr,
int len,
int type,
struct hostent *hptr,
struct hostent_data *hdptr);
[Tru64 UNIX] The following definition of the gethostbyaddr() routine
does
not conform to current standards and is supported only for backward compa-
tibility (see standards(5)):
struct hostent *gethostbyaddr(
const char *addr,
int len,
int type) ;
STANDARDS
Interfaces documented on this reference page conform to industry standards
as follows:
gethostbyaddr(): XNS4.0
Refer to the standards(5) reference page for more information about indus-
try standards and associated tags.
PARAMETERS
addr Specifies an Internet address in network order.
len Specifies the number of bytes in an Internet address.
type Specifies the Internet domain address format (AF_INET).
hdptr [Tru64 UNIX] Is data for the host database. The netdb.h header
file defines the hostent_data structure.
hptr [Tru64 UNIX] Points to the hostent structure. The netdb.h
header file defines the hostent structure.
The gethostbyaddr() routine returns a pointer to a structure of type hos-
tent. Its members specify data obtained from either the local /etc/hosts
file or one of the files distributed by DNS/BIND or NIS. To determine
which file or files to search, and in which order, the system uses the
switches in the /etc/svc.conf file. The netdb.h header file defines the
hostent structure.
The gethostbyaddr() routine searches the network host database
sequentially
until a match with the addr and type parameters occurs. The len parameter
must specify the number of bytes in an Internet address. The addr parame-
ter must specify the address in network order. The type parameter must be
the constant AF_INET, which specifies the Internet Protocol Version 4
(IPv4) address format. When EOF (End-of-File) is reached without a match,
an error value is returned.
If using DNS/BIND, the information is obtained from a name server
specified
in the /etc/resolv.conf file. When the name server is not running, the
gethostbyaddr() routine searches the local hosts name file.
Use the endhostent() routine to close the /etc/hosts file.
The gethostbyaddr() routine returns a pointer to thread-specific data.
Subsequent calls to this or a related routine from the same thread
overwrite this data.
[Tru64 UNIX] The gethostbyaddr_r() routine is an obsolete reentrant ver-
sion of the gethostbyaddr() routine. It is supported in order to maintain
backward compatibility with previous versions of the operating system and
should not be used in new designs. Note that you must zero-fill the hdptr
structure before its first access by the gethostbyaddr_r() routine.
RETURN VALUES
Upon successful completion, the gethostbyaddr() routine returns a pointer
to a hostent structure. If it reaches the end of the network hostname
database, it returns a null pointer.
[Tru64 UNIX] Upon successful completion, the gethostbyaddr_r() routine
stores the hostent structure in hptr, and returns a value of 0 (zero).
Upon failure, it returns a value of -1.
ERRORS
If the gethostbyaddr() or gethostbyaddr_r() routine call fails, h_errno is
set to one of the following values:
[HOST_NOT_FOUND]
Host is unknown.
[NO_DATA] The server recognized the request and the name, but no address
is
available for the name. Another type of name server request may
be successful.
[NO_RECOVERY]
An unexpected server failure occurred. This is a nonrecoverable
error.
[TRY_AGAIN]
A transient error occurred, for example, the server did not
respond. A retry at some later time may be successful.
[Tru64 UNIX] If any of the following conditions occurs, the
gethostbyaddr_r() routine sets errno to the corresponding value:
[EINVAL] The name, hptr, or hdptr is invalid, or type is not AF_INET.
[EINVAL] The name, hptr, or hdptr is invalid, or type is not AF_INET.
FILES
/etc/hosts
This file is the Internet network hostname database. Each record
in the file occupies a single line and has three fields consist-
ing of the host address, official hostname, and aliases.
/etc/resolv.conf
The resolver configuration file.
/etc/svc.conf
The database service selection configuration file.
RELATED INFORMATION
routines: endhostent(3), gethostbyname(3), sethostent(3).
Files: hosts(4), resolv.conf(4), svc.conf(4).
Networks: bind_intro(7), nis_intro(7).
Standards: standards(5)