Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A proper (even if really KISS) implementation of gras_os_myname
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 27 May 2005 19:43:13 +0000 (19:43 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 27 May 2005 19:43:13 +0000 (19:43 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1297 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
src/gras/Virtu/rl_dns.c

index 77f4f92..35a29b2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@ SimGrid (2.95) unstable; urgency=low
   * bugfix in automatic type parsing: differentiate the types "char[22]"
     and "unsigned char[22]". "short" and "long" modifiers were also ignored;
     other modifier (such as reference level) are still ignored. [MQ]
   * bugfix in automatic type parsing: differentiate the types "char[22]"
     and "unsigned char[22]". "short" and "long" modifiers were also ignored;
     other modifier (such as reference level) are still ignored. [MQ]
+  * Real (even if simplistic) implementation of gras_os_myname() on RL [MQ]
   
  -- 
 
   
  -- 
 
index a52a7bb..83ae30a 100644 (file)
@@ -8,16 +8,39 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "gras/Virtu/virtu_rl.h"
  * 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}() */
 
 
-/* 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 ;)
- */
+/* 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) {
-   return "(unknown host)";
+  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;
 }
 
 }