- if (hp) {
- n_len = strlen(hp->h_name) + 1;
- host = realloc(host, (unsigned)n_len);
-
- (void) strcpy(host, hp->h_name);
- return host;
- } else {
- /* can't get name from nameserver; fix up the format a bit */
- for (cp = host; *cp; cp++) {
- register int c; /* pcc doesn't like register char */
- if (islower(c = *cp)) *cp = toupper(c);
- has_dot |= (c == '.');
- }
- if (!has_dot) {
- 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);
+ if (hp)
+ {
+ host = realloc(host, strlen(hp->h_name) + 1);
+ if (host)
+ strcpy(host, hp->h_name);
+ return host;
+ }
+ else
+ {
+ /* can't get name from nameserver; fix up the format a bit */
+ cp = strchr(host, '.');
+ if (!cp)
+ {
+ tbuf = malloc(strlen(host) + strlen(local_domain()) + 2);
+ if (!tbuf)
+ return NULL;
+ sprintf(tbuf, "%s.%s", host, local_domain());
+ free(host);
+ host = tbuf;