3 /* rl_dns - name resolution (real life) */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "gras/Virtu/virtu_rl.h"
13 /* A portable DNS resolver is a nightmare to do in a portable manner.
14 keep it simple/stupid for now. */
16 const char *gras_os_myname(void)
18 static char *myname = NULL;
21 return (const char *) myname;
23 myname = xbt_new(char, 255);
25 if (gethostname(myname, 255) == -1) {
26 #ifdef HAVE_SYS_SOCKET_H
27 /* gethostname() failed! Trying with localhost instead.
28 We first need to query the DNS to make sure localhost is resolved
29 See the note in nws/Portability/dnsutil.c about {end,set}hostent() */
32 tmp = gethostbyname("localhost");
36 strncat(myname, tmp->h_name, 255);
38 /* Erm. localhost cannot be resolved. There's something wrong in the user DNS setting */
39 sprintf(myname, "(misconfigured host)");
42 sprintf(myname, "(misconfigured windows host)");