X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/18d865e6985d7a5903eac874c8942b7001310625..404a5c6adee41f1161eee8e71278e2230abdd459:/src/gras/Virtu/rl_dns.c diff --git a/src/gras/Virtu/rl_dns.c b/src/gras/Virtu/rl_dns.c index 75dd9b671b..83ae30aeca 100644 --- a/src/gras/Virtu/rl_dns.c +++ b/src/gras/Virtu/rl_dns.c @@ -8,17 +8,39 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "gras/Virtu/virtu_rl.h" +#include /* {end,set}hostent() gethostby{addr,name}() */ -/* A portable DNS resolver is a nightmare to do in a portable manner */ -/* the ADNS library is a good candidate for inclusion in the source tree, but - * it would be a bit too much. We need a stripped down version of it, and it's - * a bit too late for this tonight. - * - * Next time maybe ;) - */ -const char *gras_os_myname(void) { +/* A portable DNS resolver is a nightmare to do in a portable manner. + keep it simple/stupid for now. */ - return "(unknown host)"; +const char *gras_os_myname(void) { + static char *myname = NULL; + + if (myname) + return (const char*) myname; + + myname = xbt_new(char, 255); + + if (gethostname(myname, 255) == -1) { + /* 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 { + /* Erm. localhost cannot be resolved. There's something wrong in the user DNS setting */ + sprintf(myname, "(misconfigured host)"); + } + } + + myname[254] = '\0'; + + return myname; }