]> andersk Git - moira.git/blobdiff - lib/fixhost.c
line buffer the output
[moira.git] / lib / fixhost.c
index 2803aece5b43524f7013f8ccd6b1edaac0a5dfb0..50c39080f8cf28503f0d8db1f7b44738f4273a2e 100644 (file)
@@ -16,20 +16,14 @@ static char *rcsid_fixhost_c = "$Header$";
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/nameser.h>
-#ifdef sun
-#include <resolv.h>
-#else
-#include <arpa/resolv.h>
-#endif sun
 #include <netdb.h>
 #include <stdio.h>
 #include <strings.h>
 #include <ctype.h>
+#include <moira.h>
 
 extern char *malloc();
 extern char *realloc();
-extern char *strsave();
 
 /*
  * Canonicalize hostname:
@@ -59,7 +53,7 @@ canonicalize_hostname(host)
        return(strsave(tbuf));
     }
 
-    if (index(host, '*') || index(host, '?'))
+    if (index(host, '*') || index(host, '?') || index(host, '['))
       return(host);
 
     hp = gethostbyname(host);
@@ -78,7 +72,18 @@ canonicalize_hostname(host)
            has_dot |= (c == '.');
        }
        if (!has_dot) {
-           (void) sprintf(tbuf, "%s.%s", host, _res.defdname);
+           static char *domain = NULL;
+
+           if (domain == NULL) {
+               gethostname(tbuf, sizeof(tbuf));
+               hp = gethostbyname(tbuf);
+               cp = index(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.032869 seconds and 4 git commands to generate.