Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics (giva a name to a struct)
[simgrid.git] / src / gras / Virtu / rl_dns.c
index 83ae30a..61f1867 100644 (file)
@@ -8,21 +8,22 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "gras/Virtu/virtu_rl.h"
-#include <netdb.h>  /* {end,set}hostent() gethostby{addr,name}() */
-
+#include "portable.h"
 
 /* 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. 
        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() */
@@ -30,17 +31,19 @@ const char *gras_os_myname(void) {
     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
   }
-   
+
   myname[254] = '\0';
+
   return myname;
 }
-