]> andersk Git - moira.git/blobdiff - lib/fixhost.c
fixed a cast
[moira.git] / lib / fixhost.c
index 5ab6dd0a67c2a39b0405c3b92a858422edadba48..54bc7205408ddb6629730c313a8426597cf8fc87 100644 (file)
@@ -16,16 +16,17 @@ static char *rcsid_fixhost_c = "$Header$";
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <arpa/resolv.h>
 #include <netdb.h>
 #include <stdio.h>
-#include <strings.h>
+#ifdef POSIX
+#include <sys/utsname.h>
+#endif
+#include <string.h>
 #include <ctype.h>
+#include <moira.h>
 
 extern char *malloc();
 extern char *realloc();
-extern char *strsave();
 
 /*
  * Canonicalize hostname:
@@ -46,6 +47,9 @@ canonicalize_hostname(host)
     int n_len;
     int has_dot = 0;
     char tbuf[BUFSIZ];
+#ifdef POSIX
+    struct utsname name;
+#endif
     register char *cp;
     
     if (strlen(host) > 2 && host[0] == '"' && host[strlen(host)-1] == '"') {
@@ -55,7 +59,7 @@ canonicalize_hostname(host)
        return(strsave(tbuf));
     }
 
-    if (index(host, '*') || index(host, '?'))
+    if (strchr(host, '*') || strchr(host, '?') || strchr(host, '['))
       return(host);
 
     hp = gethostbyname(host);
@@ -74,7 +78,23 @@ canonicalize_hostname(host)
            has_dot |= (c == '.');
        }
        if (!has_dot) {
-           (void) sprintf(tbuf, "%s.%s", host, _res.defdname);
+           static char *domain = NULL;
+
+           if (domain == NULL) {
+#ifdef POSIX
+               (void) uname(&name);
+               strncpy(tbuf, name.nodename, sizeof(tbuf));
+#else
+               gethostname(tbuf, sizeof(tbuf));
+#endif
+               hp = gethostbyname(tbuf);
+               cp = strchr(hp->h_name, '.');
+               if (cp)
+                 domain = strsave(++cp);
+               else
+                 domain = "";
+           }
+           (void) sprintf(tbuf, "%s.%s", host, domain);
            free(host);
            host = strsave(tbuf);
        }
This page took 0.034962 seconds and 4 git commands to generate.