]> andersk Git - moira.git/blobdiff - lib/fixhost.c
posixify source
[moira.git] / lib / fixhost.c
index 50c39080f8cf28503f0d8db1f7b44738f4273a2e..54bc7205408ddb6629730c313a8426597cf8fc87 100644 (file)
@@ -18,7 +18,10 @@ static char *rcsid_fixhost_c = "$Header$";
 #include <netinet/in.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>
 
@@ -44,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] == '"') {
@@ -53,7 +59,7 @@ canonicalize_hostname(host)
        return(strsave(tbuf));
     }
 
-    if (index(host, '*') || index(host, '?') || index(host, '['))
+    if (strchr(host, '*') || strchr(host, '?') || strchr(host, '['))
       return(host);
 
     hp = gethostbyname(host);
@@ -75,9 +81,14 @@ canonicalize_hostname(host)
            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 = index(hp->h_name, '.');
+               cp = strchr(hp->h_name, '.');
                if (cp)
                  domain = strsave(++cp);
                else
This page took 0.496415 seconds and 4 git commands to generate.