]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/mts/sendmail/hosts.c
1 /* hosts.c - find out the official name of a host */
3 static char ident
[] = "@(#)$Id: hosts.c,v 1.7 1992/12/15 00:20:22 jromine Exp $";
8 /* In the SendMail world, we really don't know what the valid hosts are.
9 We could poke around in the sendmail.cf file, but that still isn't a
10 guarantee. As a result, we'll say that everything is a valid host, and
11 let SendMail worry about it. */
14 #include "../h/strings.h"
16 #include "../zotnet/mts.h"
18 #if defined(BSD42) || defined(SOCKETS)
20 #endif /* BSD42 or SOCKETS */
38 char *OfficialName (name
)
44 #if defined(BSD42) || defined(SOCKETS)
45 register struct hostent
*hp
;
46 #endif /* BSD42 or SOCKETS */
47 static char buffer
[BUFSIZ
];
49 register struct host
*h
;
51 for (p
= name
, q
= site
; *p
; p
++, q
++)
52 *q
= isupper (*p
) ? tolower (*p
) : *p
;
56 if (uleq (LocalName (), site
))
60 if (rhost (&q
) != NOTOK
) {
61 (void) strcpy (buffer
, q
);
66 #if defined(BSD42) || defined(SOCKETS)
70 if (hp
= gethostbyname (q
)) {
71 (void) strcpy (buffer
, hp
-> h_name
);
74 #endif /* BSD42 or SOCKETS */
76 if (hosts
.h_name
|| init_hs ())
77 for (h
= hosts
.h_next
; h
; h
= h
-> h_next
)
78 if (uleq (h
-> h_name
, q
))
81 for (r
= h
-> h_aliases
; *r
; r
++)
85 (void) strcpy (buffer
, site
);
91 /* Use hostable as an exception file for those hosts that aren't on the
92 Internet (listed in /etc/hosts). These are usually PhoneNet and UUCP
98 static int init_hs () {
105 register struct host
*h
;
108 if ((fp
= fopen (hostable
, "r")) == NULL
)
112 while (fgets (buffer
, sizeof buffer
, fp
) != NULL
) {
113 if (cp
= index (buffer
, '#'))
115 if (cp
= index (buffer
, '\n'))
117 for (cp
= buffer
; *cp
; cp
++)
120 for (cp
= buffer
; isspace (*cp
); cp
++)
126 if (cp
= index (dp
= cp
, ' ')) {
128 for (cp
++; *cp
; cp
++) {
129 while (isspace (*cp
))
133 if (cp
= index (*q
++ = cp
, ' '))
137 if (q
>= aliases
+ NALIASES
)
144 h
-> h_next
= (struct host
*) calloc (1, sizeof *h
);
146 h
-> h_name
= getcpy (dp
);
148 (char **) calloc ((unsigned) (q
- aliases
+ 1), sizeof *q
);
149 for (q
= aliases
; *q
; q
++)