]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/mts/mh/hosts.c
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / mts / mh / hosts.c
1 /* hosts.c - find out the official name of a host */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: hosts.c,v 1.6 1992/12/15 00:20:22 jromine Exp $";
4 #endif /* lint */
5
6 /* LINTLIBRARY */
7
8 #undef NETWORK
9 #if defined(BSD41A) || defined(BSD42) || defined(SOCKETS)
10 #define NETWORK
11 #endif /* not (defined(BSD41A) || defined(BSD42) || defined(SOCKETS)) */
12
13 #include "../h/strings.h"
14 #include <stdio.h>
15 #include "../zotnet/mts.h"
16 #include <ctype.h>
17 #if defined(BSD42) || defined(SOCKETS)
18 #include <netdb.h>
19 #endif /* BSD42 or SOCKETS */
20
21
22 #define NOTOK (-1)
23
24 /* \f */
25
26 char *OfficialName (name)
27 char *name;
28 {
29 register char *p;
30 char *q,
31 site[BUFSIZ];
32 #ifdef NETWORK
33 static char buffer[BUFSIZ];
34 #if defined(BSD42) || defined(SOCKETS)
35 register struct hostent *hp;
36 #endif /* BSD42 or SOCKETS */
37 #endif /* NETWORK */
38
39 for (p = name, q = site; *p; p++, q++)
40 *q = isupper (*p) ? tolower (*p) : *p;
41 *q = 0;
42 q = site;
43
44 if (uleq (LocalName (), site))
45 return LocalName ();
46
47 #ifdef BSD41A
48 if (rhost (&q) != NOTOK) {
49 (void) strcpy (buffer, q);
50 free (q);
51 return buffer;
52 }
53 #endif /* BSD41A */
54 #if defined(BSD42) || defined(SOCKETS)
55 if (hp = gethostbyname (q)) {
56 (void) strcpy (buffer, hp -> h_name);
57 return buffer;
58 }
59 #endif /* BSD42 or SOCKETS */
60
61 return NULL;
62 }