]>
diplodocus.org Git - nmh/blob - mts/smtp/hosts.c
3 * hosts.c -- find out the official name of a host
9 * In the SendMail world, we really don't know what the valid
10 * hosts are. We could poke around in the sendmail.cf file, but
11 * that still isn't a guarantee. As a result, we'll say that
12 * everything is a valid host, and let SendMail worry about it.
16 #include <zotnet/mts/mts.h>
29 static int init_hs(void);
33 OfficialName (char *name
)
35 char *p
, *q
, site
[BUFSIZ
];
38 static char buffer
[BUFSIZ
];
42 for (p
= name
, q
= site
; *p
&& (q
- site
< sizeof(site
) - 1); p
++, q
++)
43 *q
= isupper (*p
) ? tolower (*p
) : *p
;
47 if (!strcasecmp (LocalName(), site
))
50 #ifdef HAVE_SETHOSTENT
54 if ((hp
= gethostbyname (q
))) {
55 strncpy (buffer
, hp
->h_name
, sizeof(buffer
));
58 if (hosts
.h_name
|| init_hs ()) {
59 for (h
= hosts
.h_next
; h
; h
= h
->h_next
)
60 if (!strcasecmp (h
->h_name
, q
)) {
63 for (r
= h
->h_aliases
; *r
; r
++)
64 if (!strcasecmp (*r
, q
))
69 strncpy (buffer
, site
, sizeof(buffer
));
74 * Use hostable as an exception file for those hosts that aren't
75 * on the Internet (listed in /etc/hosts). These are usually
76 * PhoneNet and UUCP sites.
84 char *cp
, *dp
, **q
, **r
;
85 char buffer
[BUFSIZ
], *aliases
[NALIASES
];
86 register struct host
*h
;
89 if ((fp
= fopen (hostable
, "r")) == NULL
)
93 while (fgets (buffer
, sizeof(buffer
), fp
) != NULL
) {
94 if ((cp
= strchr(buffer
, '#')))
96 if ((cp
= strchr(buffer
, '\n')))
98 for (cp
= buffer
; *cp
; cp
++)
101 for (cp
= buffer
; isspace (*cp
); cp
++)
107 if ((cp
= strchr(dp
= cp
, ' '))) {
109 for (cp
++; *cp
; cp
++) {
110 while (isspace (*cp
))
114 if ((cp
= strchr(*q
++ = cp
, ' ')))
118 if (q
>= aliases
+ NALIASES
)
125 h
->h_next
= (struct host
*) calloc (1, sizeof(*h
));
127 h
->h_name
= getcpy (dp
);
129 (char **) calloc ((size_t) (q
- aliases
+ 1), sizeof(*q
));
130 for (q
= aliases
; *q
; q
++)