X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/95d328f9ca4dd6ccd2065c6c84aca83d43001804..dff9e15c44ab6340d27215957c56fa72fad246a2:/src/gras/Virtu/rl_dns.c diff --git a/src/gras/Virtu/rl_dns.c b/src/gras/Virtu/rl_dns.c index 04e2f5408b..61f1867c5c 100644 --- a/src/gras/Virtu/rl_dns.c +++ b/src/gras/Virtu/rl_dns.c @@ -13,37 +13,37 @@ /* A portable DNS resolver is a nightmare to do in a portable manner. keep it simple/stupid for now. */ -const char *gras_os_myname(void) { +const char *gras_os_myname(void) +{ static char *myname = NULL; - + if (myname) - return (const char*) myname; - + return (const char *) myname; + myname = xbt_new(char, 255); - + if (gethostname(myname, 255) == -1) { #ifdef HAVE_SYS_SOCKET_H - /* gethostname() failed! Trying with localhost instead. + /* gethostname() failed! Trying with localhost instead. We first need to query the DNS to make sure localhost is resolved See the note in nws/Portability/dnsutil.c about {end,set}hostent() */ struct hostent *tmp; sethostent(0); tmp = gethostbyname("localhost"); endhostent(); - + if (tmp) { strncat(myname, tmp->h_name, 255); - } else { + } else { /* Erm. localhost cannot be resolved. There's something wrong in the user DNS setting */ sprintf(myname, "(misconfigured host)"); } #else - sprintf(myname, "(misconfigured windows host)"); -#endif + sprintf(myname, "(misconfigured windows host)"); +#endif } - + myname[254] = '\0'; - + return myname; } -