- if (!has_dot) {
- (void) sprintf(tbuf, "%s.%s", host, _res.defdname);
- free(host);
- host = strsave(tbuf);
+ if (!has_dot)
+ {
+ static char *domain = NULL;
+
+ if (domain == NULL)
+ {
+ char hostbuf[256];
+
+ if (mr_host(hostbuf, sizeof(hostbuf)) == MR_SUCCESS)
+ {
+ cp = strchr(hostbuf, '.');
+ if (cp)
+ domain = strdup(++cp);
+ }
+ else
+ {
+ struct utsname name;
+ uname(&name);
+ hp = gethostbyname(name.nodename);
+ if (hp)
+ {
+ cp = strchr(hp->h_name, '.');
+ if (cp)
+ domain = strdup(++cp);
+ }
+ }
+ if (!domain)
+ domain = "";
+ }
+ tbuf = malloc(strlen(host) + strlen(domain) + 2);
+ if (!tbuf)
+ return NULL;
+ sprintf(tbuf, "%s.%s", host, domain);
+ free(host);
+ host = tbuf;