* gethostbyname
@ 2000-12-15 21:41 Stefan Schwarzer
2000-12-19 22:14 ` gethostbyname Joe Mario
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schwarzer @ 2000-12-15 21:41 UTC (permalink / raw)
Maybe there is a Compaq network guru 'listening':
I observed an oddity using gethostbyname on a True64 5.0/910 host
Trying to set up two connected sockets for testing on the same host, I
needed to figure out the address of the local host and coded up
something along the lines of (simplified, modulo typos):
#include <netdb.h> // gethostbyname
#include <unistd.h> // close, gethostname
#include <stdio.h>
int main(){
const int hlen = 129;
char hostname[hlen];
struct hostent * pHost;
gethostname( hostname, hlen ); /* this call is ok and delivers
the official IP name of the host */
h_errno = 0; /* safety measure */
/* this should set h_errno to NETDB_SUCCESS (happens to be 0) on
success: */
pHost = gethostbyname( hostname );
printf ( "value of h_errno: %d %d\n", h_errno , NETDB_SUCCESS );
}
On 4.0 machines, the program prints ... 0 0 as I'd expect, on the
5.0/910 host I get ... 1 0 (meaning HOST_NOT_FOUND). I made sure that
the gethostname call succeeds and the name is a legal address
(manul.ica1.uni-stuttgart.de), resolved by nslookup.
The binary address returned in pHost seems to be ok in the cases
that I have tested.
If I'd written 'gethostbyname' I'd consider this a bug.
--
Stefan Schwarzer office: +49-(0)711-685-7606 fax: x-3658
Uni Stuttgart, ICA 1 (?-
Pfaffenwaldring 27 //\ sts@ica1.uni-stuttgart.de
70569 Stuttgart, Germany -V_/---- http://www.ica1.uni-stuttgart.de/~sts
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: gethostbyname
2000-12-15 21:41 gethostbyname Stefan Schwarzer
@ 2000-12-19 22:14 ` Joe Mario
0 siblings, 0 replies; 2+ messages in thread
From: Joe Mario @ 2000-12-19 22:14 UTC (permalink / raw)
Cc: Stefan Schwarzer
Starting in V5.0, gethostbyname and gethostbyaddr became thread safe
by default. As a result h_errno handling became thread safe as well.
The global h_errno was left behind, but we can not guarantee it's
acuracy.
To get the thread value you need a prototype and to use the
_Get_h_errno() function, like this:
extern int _Get_h_errno();
main () {
gethostbyname(host);
if (_Get_h_errno() > 0)
herror();
}
To set h_error, applications should use _Set_h_errno(error) with the
following prototype:
extern int _Set_h_errno();
Using _Get_h_errno() returns 0 as expected.
Joe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-12-19 22:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-12-15 21:41 gethostbyname Stefan Schwarzer
2000-12-19 22:14 ` gethostbyname Joe Mario
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox