1 /* rl_dns - name resolution (real life) */
3 /* Copyright (c) 2005, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "gras/Virtu/virtu_rl.h"
12 /* A portable DNS resolver is a nightmare to do in a portable manner.
13 keep it simple/stupid for now. */
15 const char *gras_os_myname(void)
17 static char myname[255];
18 static int initialized = 0;
23 if (gethostname(myname, 255) == -1) {
24 #ifdef HAVE_SYS_SOCKET_H
25 /* gethostname() failed! Trying with localhost instead.
26 We first need to query the DNS to make sure localhost is resolved
27 See the note in nws/Portability/dnsutil.c about {end,set}hostent() */
30 tmp = gethostbyname("localhost");
34 strncpy(myname, tmp->h_name, 255);
36 /* Erm. localhost cannot be resolved. There's something wrong in the user DNS setting */
37 sprintf(myname, "(misconfigured host)");
40 sprintf(myname, "(misconfigured windows host)");