Add an entry for README.manpages
[mmh] / mts / mmdf / hosts.c
1
2 /*
3  * hosts.c -- use MMDF to get hostname information
4  *
5  * $Id$
6  */
7
8 #include "../../h/strings.h"
9 #include "util.h"
10 #include "mmdf.h"
11 #include "ch.h"
12
13 #ifdef MMDFII
14 # include "dm.h"
15 #endif /* MMDFII */
16
17 #include <mts/generic/mts.h>
18
19 /* 
20  * We really should be careful with the number of fd's that this routine
21  * opens:  the ch_seq ch_table.c module likes to keep 6 (yes, SIX) fds around
22  * to speed-up host lookups in the channel table.  Unfortunately, after all
23  * of them get opened, six are always open (ch_table may close one to open
24  * another).  The bottom line is that if repl calls post, then we get 12
25  * (yes, TWELVE) fds open, with only six usable.
26  *
27  * send will close all fds >= 3 prior to invoking post.  It would be nice
28  * if one could control ch_seq's use of fds for table lookups, but such is
29  * life.
30  *
31  */
32
33 #ifndef MMDFII
34 char *
35 OfficialName (char *name)
36 {
37     register Chan *ch;
38     static char buffer[BUFSIZ];
39
40     return ((ch = ch_h2chan (name, buffer)) == (Chan *) (-1) ? NULL
41             : ch == (Chan *) NULL ? LocalName ()
42             : buffer);
43 }
44 #else   /* MMDFII */
45
46 extern char *invo_name;
47
48 extern short ch_yloc;            /* ok to intercept local names */
49
50 static int inited = 0;
51
52 char *
53 OfficialName (char *name)
54 {
55     Dmn_route route;
56     static char buffer[BUFSIZ];
57
58     if (!inited) {
59         mmdf_init (invo_name);
60         inited = 1;
61     }
62     switch (dm_v2route (name, buffer, &route)) {
63         case NOTOK: 
64         case OK: 
65             return ((ch_yloc && lexequ (name, LocalName ())) ? LocalName ()
66                     : NULL);
67
68         default: 
69             return buffer;
70     }
71 }
72 #endif  /* MMDFII */