3 * hosts.c -- find out the official name of a host
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 * In the SendMail world, we really don't know what the valid
14 * hosts are. We could poke around in the sendmail.cf file, but
15 * that still isn't a guarantee. As a result, we'll say that
16 * everything is a valid host, and let SendMail worry about it.
33 static int init_hs(void);
37 OfficialName (char *name)
40 char *q, site[BUFSIZ];
41 struct addrinfo hints, *res;
43 static char buffer[BUFSIZ];
47 for (p = name, q = site; *p && (q - site < sizeof(site) - 1); p++, q++)
48 *q = isupper (*p) ? tolower (*p) : *p;
52 if (!mh_strcasecmp (LocalName(), site))
55 memset(&hints, 0, sizeof(hints));
56 hints.ai_flags = AI_CANONNAME;
57 hints.ai_family = PF_UNSPEC;
59 if (getaddrinfo(q, NULL, &hints, &res) == 0) {
60 strncpy (buffer, res->ai_canonname, sizeof(buffer));
61 buffer[sizeof(buffer) - 1] = '\0';
65 if (hosts.h_name || init_hs ()) {
66 for (h = hosts.h_next; h; h = h->h_next)
67 if (!mh_strcasecmp (h->h_name, q)) {
70 for (r = h->h_aliases; *r; r++)
71 if (!mh_strcasecmp (*r, q))
76 strncpy (buffer, site, sizeof(buffer));
81 * Use hostable as an exception file for those hosts that aren't
82 * on the Internet (listed in /etc/hosts). These are usually
83 * PhoneNet and UUCP sites.
93 char buffer[BUFSIZ], *aliases[NALIASES];
94 register struct host *h;
97 if ((fp = fopen (hostable, "r")) == NULL)
101 while (fgets (buffer, sizeof(buffer), fp) != NULL) {
102 if ((cp = strchr(buffer, '#')))
104 if ((cp = strchr(buffer, '\n')))
106 for (cp = buffer; *cp; cp++)
109 for (cp = buffer; isspace (*cp); cp++)
115 if ((cp = strchr(dp = cp, ' '))) {
117 for (cp++; *cp; cp++) {
118 while (isspace (*cp))
122 if ((cp = strchr(*q++ = cp, ' ')))
126 if (q >= aliases + NALIASES)
133 h->h_next = (struct host *) calloc (1, sizeof(*h));
135 h->h_name = getcpy (dp);
137 (char **) calloc ((size_t) (q - aliases + 1), sizeof(*q));
138 for (q = aliases; *q; q++)