add icmp statistics printing
[unix-history] / usr / src / usr.bin / tip / remote.c
CommitLineData
3f48242d 1/* remote.c 4.5 81/11/29 */
8274ea85
BJ
2# include "tip.h"
3
4/*
5 * Attributes to be gleened from remote host description
6 * data base.
7 */
8static char **caps[] = {
9 &AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN
10};
11
12static char *capstrings[] = {
13 "at", "dv", "cm", "cu", "el", "ie", "oe", "pn", 0
14};
15
16char *rgetstr();
17
18static
19getremcap(host)
20 register char *host;
21{
22 int stat;
23 char tbuf[BUFSIZ];
24 static char buf[BUFSIZ/2];
25 char *bp = buf;
26 register char **p, ***q;
27
28 if ((stat = rgetent(tbuf, host)) <= 0) {
29 fprintf(stderr, stat == 0 ?
30 "tip: unknown host %s\n" :
31 "tip: can't open host description file\n", host);
32 exit(3);
33 }
34
35 for (p = capstrings, q = caps; *p != NULL; p++, q++)
3f48242d
SL
36 if (**q == NULL)
37 **q = rgetstr(*p, &bp);
38 if (!BR && (BR = rgetnum("br")) < 0)
8274ea85
BJ
39 BR = DEFBR;
40 if ((FS = rgetnum("fs")) < 0)
41 FS = DEFFS;
3f48242d
SL
42 if (DU < 0)
43 DU = 0;
44 else
45 DU = rgetflag("du");
8274ea85
BJ
46 if (DV == NOSTR) {
47 fprintf(stderr, "%s: missing device spec\n", host);
48 exit(3);
49 }
50 if (DU && CU == NOSTR)
51 CU = DV;
52 if (DU && PN == NOSTR) {
53 fprintf(stderr, "%s: missing phone number\n", host);
54 exit(3);
55 }
3e90c816
SL
56 /*
57 * This effectively eliminates the "hw" attribute
58 * from the description file
59 */
60 if (!HW)
61 HW = (CU == NOSTR) || (DU && equal(DV, CU));
8274ea85
BJ
62 HO = host;
63}
64
65char *
66getremote(host)
67 char *host;
68{
69 register char *cp;
70 static char *next;
71 static int lookedup = 0;
72
73 if (!lookedup) {
74 if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
75 fprintf(stderr, "tip: no host specified\n");
76 exit(3);
77 }
78 getremcap(host);
79 next = DV;
80 lookedup++;
81 }
82 /*
83 * We return a new device each time we're called (to allow
84 * a rotary action to be simulated)
85 */
86 if (next == NOSTR)
3f48242d 87 return (NOSTR);
8274ea85
BJ
88 if ((cp = index(next, ',')) == NULL) {
89 DV = next;
90 next = NOSTR;
91 } else {
92 *cp++ = '\0';
93 DV = next;
94 next = cp;
95 }
3f48242d 96 return (DV);
8274ea85 97}