#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
-#include <arpa/nameser.h>
-#if defined(sun) || defined(AIX386)
-#include <resolv.h>
-#else
-#include <arpa/resolv.h>
-#endif
#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:
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] == '"') {
return(strsave(tbuf));
}
- if (index(host, '*') || index(host, '?') || index(host, '['))
+ if (strchr(host, '*') || strchr(host, '?') || strchr(host, '['))
return(host);
hp = gethostbyname(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);
}