Mon Dec 14 00:49:46 2009 UTC ()
constify


(christos)
diff -r1.1.1.1 -r1.2 src/external/bsd/ntp/dist/ntpq/ntpq-subs.c

cvs diff -r1.1.1.1 -r1.2 src/external/bsd/ntp/dist/ntpq/ntpq-subs.c (switch to unified diff)

--- src/external/bsd/ntp/dist/ntpq/ntpq-subs.c 2009/12/13 16:56:29 1.1.1.1
+++ src/external/bsd/ntp/dist/ntpq/ntpq-subs.c 2009/12/14 00:49:45 1.2
@@ -1,1015 +1,1015 @@ @@ -1,1015 +1,1015 @@
1/* $NetBSD: ntpq-subs.c,v 1.1.1.1 2009/12/13 16:56:29 kardel Exp $ */ 1/* $NetBSD: ntpq-subs.c,v 1.2 2009/12/14 00:49:45 christos Exp $ */
2 2
3/* 3/*
4 * ntpq_ops.c - subroutines which are called to perform operations by ntpq 4 * ntpq_ops.c - subroutines which are called to perform operations by ntpq
5 */ 5 */
6 6
7#include <stdio.h> 7#include <stdio.h>
8#include <ctype.h> 8#include <ctype.h>
9#include <sys/types.h> 9#include <sys/types.h>
10#include <sys/time.h> 10#include <sys/time.h>
11 11
12#include "ntp_stdlib.h" 12#include "ntp_stdlib.h"
13#include "ntpq.h" 13#include "ntpq.h"
14#include "ntpq-opts.h" 14#include "ntpq-opts.h"
15 15
16extern char * chosts[]; 16extern const char * chosts[];
17extern char currenthost[]; 17extern char currenthost[];
18extern int numhosts; 18extern int numhosts;
19int maxhostlen; 19int maxhostlen;
20 20
21/* 21/*
22 * Declarations for command handlers in here 22 * Declarations for command handlers in here
23 */ 23 */
24static int checkassocid (u_int32); 24static int checkassocid (u_int32);
25static struct varlist *findlistvar (struct varlist *, char *); 25static struct varlist *findlistvar (struct varlist *, char *);
26static void doaddvlist (struct varlist *, char *); 26static void doaddvlist (struct varlist *, char *);
27static void dormvlist (struct varlist *, char *); 27static void dormvlist (struct varlist *, char *);
28static void doclearvlist (struct varlist *); 28static void doclearvlist (struct varlist *);
29static void makequerydata (struct varlist *, int *, char *); 29static void makequerydata (struct varlist *, int *, char *);
30static int doquerylist (struct varlist *, int, int, int,  30static int doquerylist (struct varlist *, int, int, int,
31 u_short *, int *, char **); 31 u_short *, int *, char **);
32static void doprintvlist (struct varlist *, FILE *); 32static void doprintvlist (struct varlist *, FILE *);
33static void addvars (struct parse *, FILE *); 33static void addvars (struct parse *, FILE *);
34static void rmvars (struct parse *, FILE *); 34static void rmvars (struct parse *, FILE *);
35static void clearvars (struct parse *, FILE *); 35static void clearvars (struct parse *, FILE *);
36static void showvars (struct parse *, FILE *); 36static void showvars (struct parse *, FILE *);
37static int dolist (struct varlist *, int, int, int, 37static int dolist (struct varlist *, int, int, int,
38 FILE *); 38 FILE *);
39static void readlist (struct parse *, FILE *); 39static void readlist (struct parse *, FILE *);
40static void writelist (struct parse *, FILE *); 40static void writelist (struct parse *, FILE *);
41static void readvar (struct parse *, FILE *); 41static void readvar (struct parse *, FILE *);
42static void writevar (struct parse *, FILE *); 42static void writevar (struct parse *, FILE *);
43static void clocklist (struct parse *, FILE *); 43static void clocklist (struct parse *, FILE *);
44static void clockvar (struct parse *, FILE *); 44static void clockvar (struct parse *, FILE *);
45static int findassidrange (u_int32, u_int32, int *, int *); 45static int findassidrange (u_int32, u_int32, int *, int *);
46static void mreadlist (struct parse *, FILE *); 46static void mreadlist (struct parse *, FILE *);
47static void mreadvar (struct parse *, FILE *); 47static void mreadvar (struct parse *, FILE *);
48static int dogetassoc (FILE *); 48static int dogetassoc (FILE *);
49static void printassoc (int, FILE *); 49static void printassoc (int, FILE *);
50static void associations (struct parse *, FILE *); 50static void associations (struct parse *, FILE *);
51static void lassociations (struct parse *, FILE *); 51static void lassociations (struct parse *, FILE *);
52static void passociations (struct parse *, FILE *); 52static void passociations (struct parse *, FILE *);
53static void lpassociations (struct parse *, FILE *); 53static void lpassociations (struct parse *, FILE *);
54 54
55#ifdef UNUSED 55#ifdef UNUSED
56static void radiostatus (struct parse *, FILE *); 56static void radiostatus (struct parse *, FILE *);
57#endif /* UNUSED */ 57#endif /* UNUSED */
58 58
59static void pstatus (struct parse *, FILE *); 59static void pstatus (struct parse *, FILE *);
60static long when (l_fp *, l_fp *, l_fp *); 60static long when (l_fp *, l_fp *, l_fp *);
61static char * prettyinterval (char *, long); 61static char * prettyinterval (char *, long);
62static int doprintpeers (struct varlist *, int, int, int, char *, FILE *, int); 62static int doprintpeers (struct varlist *, int, int, int, char *, FILE *, int);
63static int dogetpeers (struct varlist *, int, FILE *, int); 63static int dogetpeers (struct varlist *, int, FILE *, int);
64static void dopeers (int, FILE *, int); 64static void dopeers (int, FILE *, int);
65static void peers (struct parse *, FILE *); 65static void peers (struct parse *, FILE *);
66static void lpeers (struct parse *, FILE *); 66static void lpeers (struct parse *, FILE *);
67static void doopeers (int, FILE *, int); 67static void doopeers (int, FILE *, int);
68static void opeers (struct parse *, FILE *); 68static void opeers (struct parse *, FILE *);
69static void lopeers (struct parse *, FILE *); 69static void lopeers (struct parse *, FILE *);
70static void config (struct parse *, FILE *); 70static void config (struct parse *, FILE *);
71static void saveconfig (struct parse *, FILE *); 71static void saveconfig (struct parse *, FILE *);
72static void config_from_file(struct parse *, FILE *); 72static void config_from_file(struct parse *, FILE *);
73 73
74 74
75/* 75/*
76 * Commands we understand. Ntpdc imports this. 76 * Commands we understand. Ntpdc imports this.
77 */ 77 */
78struct xcmd opcmds[] = { 78struct xcmd opcmds[] = {
79 { "saveconfig", saveconfig, { NTP_STR, NO, NO, NO }, 79 { "saveconfig", saveconfig, { NTP_STR, NO, NO, NO },
80 { "filename", "", "", ""},  80 { "filename", "", "", ""},
81 "save ntpd configuration to file, . for current config file"}, 81 "save ntpd configuration to file, . for current config file"},
82 { "associations", associations, { NO, NO, NO, NO }, 82 { "associations", associations, { NO, NO, NO, NO },
83 { "", "", "", "" }, 83 { "", "", "", "" },
84 "print list of association ID's and statuses for the server's peers" }, 84 "print list of association ID's and statuses for the server's peers" },
85 { "passociations", passociations, { NO, NO, NO, NO }, 85 { "passociations", passociations, { NO, NO, NO, NO },
86 { "", "", "", "" }, 86 { "", "", "", "" },
87 "print list of associations returned by last associations command" }, 87 "print list of associations returned by last associations command" },
88 { "lassociations", lassociations, { NO, NO, NO, NO }, 88 { "lassociations", lassociations, { NO, NO, NO, NO },
89 { "", "", "", "" }, 89 { "", "", "", "" },
90 "print list of associations including all client information" }, 90 "print list of associations including all client information" },
91 { "lpassociations", lpassociations, { NO, NO, NO, NO }, 91 { "lpassociations", lpassociations, { NO, NO, NO, NO },
92 { "", "", "", "" }, 92 { "", "", "", "" },
93 "print last obtained list of associations, including client information" }, 93 "print last obtained list of associations, including client information" },
94 { "addvars", addvars, { NTP_STR, NO, NO, NO }, 94 { "addvars", addvars, { NTP_STR, NO, NO, NO },
95 { "name[=value][,...]", "", "", "" }, 95 { "name[=value][,...]", "", "", "" },
96 "add variables to the variable list or change their values" }, 96 "add variables to the variable list or change their values" },
97 { "rmvars", rmvars, { NTP_STR, NO, NO, NO }, 97 { "rmvars", rmvars, { NTP_STR, NO, NO, NO },
98 { "name[,...]", "", "", "" }, 98 { "name[,...]", "", "", "" },
99 "remove variables from the variable list" }, 99 "remove variables from the variable list" },
100 { "clearvars", clearvars, { NO, NO, NO, NO }, 100 { "clearvars", clearvars, { NO, NO, NO, NO },
101 { "", "", "", "" }, 101 { "", "", "", "" },
102 "remove all variables from the variable list" }, 102 "remove all variables from the variable list" },
103 { "showvars", showvars, { NO, NO, NO, NO }, 103 { "showvars", showvars, { NO, NO, NO, NO },
104 { "", "", "", "" }, 104 { "", "", "", "" },
105 "print variables on the variable list" }, 105 "print variables on the variable list" },
106 { "readlist", readlist, { OPT|NTP_UINT, NO, NO, NO }, 106 { "readlist", readlist, { OPT|NTP_UINT, NO, NO, NO },
107 { "assocID", "", "", "" }, 107 { "assocID", "", "", "" },
108 "read the system or peer variables included in the variable list" }, 108 "read the system or peer variables included in the variable list" },
109 { "rl", readlist, { OPT|NTP_UINT, NO, NO, NO }, 109 { "rl", readlist, { OPT|NTP_UINT, NO, NO, NO },
110 { "assocID", "", "", "" }, 110 { "assocID", "", "", "" },
111 "read the system or peer variables included in the variable list" }, 111 "read the system or peer variables included in the variable list" },
112 { "writelist", writelist, { OPT|NTP_UINT, NO, NO, NO }, 112 { "writelist", writelist, { OPT|NTP_UINT, NO, NO, NO },
113 { "assocID", "", "", "" }, 113 { "assocID", "", "", "" },
114 "write the system or peer variables included in the variable list" }, 114 "write the system or peer variables included in the variable list" },
115 { "readvar", readvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, 115 { "readvar", readvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO },
116 { "assocID", "name=value[,...]", "", "" }, 116 { "assocID", "name=value[,...]", "", "" },
117 "read system or peer variables" }, 117 "read system or peer variables" },
118 { "rv", readvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, 118 { "rv", readvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO },
119 { "assocID", "name=value[,...]", "", "" }, 119 { "assocID", "name=value[,...]", "", "" },
120 "read system or peer variables" }, 120 "read system or peer variables" },
121 { "writevar", writevar, { NTP_UINT, NTP_STR, NO, NO }, 121 { "writevar", writevar, { NTP_UINT, NTP_STR, NO, NO },
122 { "assocID", "name=value,[...]", "", "" }, 122 { "assocID", "name=value,[...]", "", "" },
123 "write system or peer variables" }, 123 "write system or peer variables" },
124 { "mreadlist", mreadlist, { NTP_UINT, NTP_UINT, NO, NO }, 124 { "mreadlist", mreadlist, { NTP_UINT, NTP_UINT, NO, NO },
125 { "assocID", "assocID", "", "" }, 125 { "assocID", "assocID", "", "" },
126 "read the peer variables in the variable list for multiple peers" }, 126 "read the peer variables in the variable list for multiple peers" },
127 { "mrl", mreadlist, { NTP_UINT, NTP_UINT, NO, NO }, 127 { "mrl", mreadlist, { NTP_UINT, NTP_UINT, NO, NO },
128 { "assocID", "assocID", "", "" }, 128 { "assocID", "assocID", "", "" },
129 "read the peer variables in the variable list for multiple peers" }, 129 "read the peer variables in the variable list for multiple peers" },
130 { "mreadvar", mreadvar, { NTP_UINT, NTP_UINT, OPT|NTP_STR, NO }, 130 { "mreadvar", mreadvar, { NTP_UINT, NTP_UINT, OPT|NTP_STR, NO },
131 { "assocID", "assocID", "name=value[,...]", "" }, 131 { "assocID", "assocID", "name=value[,...]", "" },
132 "read peer variables from multiple peers" }, 132 "read peer variables from multiple peers" },
133 { "mrv", mreadvar, { NTP_UINT, NTP_UINT, OPT|NTP_STR, NO }, 133 { "mrv", mreadvar, { NTP_UINT, NTP_UINT, OPT|NTP_STR, NO },
134 { "assocID", "assocID", "name=value[,...]", "" }, 134 { "assocID", "assocID", "name=value[,...]", "" },
135 "read peer variables from multiple peers" }, 135 "read peer variables from multiple peers" },
136 { "clocklist", clocklist, { OPT|NTP_UINT, NO, NO, NO }, 136 { "clocklist", clocklist, { OPT|NTP_UINT, NO, NO, NO },
137 { "assocID", "", "", "" }, 137 { "assocID", "", "", "" },
138 "read the clock variables included in the variable list" }, 138 "read the clock variables included in the variable list" },
139 { "cl", clocklist, { OPT|NTP_UINT, NO, NO, NO }, 139 { "cl", clocklist, { OPT|NTP_UINT, NO, NO, NO },
140 { "assocID", "", "", "" }, 140 { "assocID", "", "", "" },
141 "read the clock variables included in the variable list" }, 141 "read the clock variables included in the variable list" },
142 { "clockvar", clockvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, 142 { "clockvar", clockvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO },
143 { "assocID", "name=value[,...]", "", "" }, 143 { "assocID", "name=value[,...]", "", "" },
144 "read clock variables" }, 144 "read clock variables" },
145 { "cv", clockvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO }, 145 { "cv", clockvar, { OPT|NTP_UINT, OPT|NTP_STR, NO, NO },
146 { "assocID", "name=value[,...]", "", "" }, 146 { "assocID", "name=value[,...]", "", "" },
147 "read clock variables" }, 147 "read clock variables" },
148 { "pstatus", pstatus, { NTP_UINT, NO, NO, NO }, 148 { "pstatus", pstatus, { NTP_UINT, NO, NO, NO },
149 { "assocID", "", "", "" }, 149 { "assocID", "", "", "" },
150 "print status information returned for a peer" }, 150 "print status information returned for a peer" },
151 { "peers", peers, { OPT|IP_VERSION, NO, NO, NO }, 151 { "peers", peers, { OPT|IP_VERSION, NO, NO, NO },
152 { "-4|-6", "", "", "" }, 152 { "-4|-6", "", "", "" },
153 "obtain and print a list of the server's peers [IP version]" }, 153 "obtain and print a list of the server's peers [IP version]" },
154 { "lpeers", lpeers, { OPT|IP_VERSION, NO, NO, NO }, 154 { "lpeers", lpeers, { OPT|IP_VERSION, NO, NO, NO },
155 { "-4|-6", "", "", "" }, 155 { "-4|-6", "", "", "" },
156 "obtain and print a list of all peers and clients [IP version]" }, 156 "obtain and print a list of all peers and clients [IP version]" },
157 { "opeers", opeers, { OPT|IP_VERSION, NO, NO, NO }, 157 { "opeers", opeers, { OPT|IP_VERSION, NO, NO, NO },
158 { "-4|-6", "", "", "" }, 158 { "-4|-6", "", "", "" },
159 "print peer list the old way, with dstadr shown rather than refid [IP version]" }, 159 "print peer list the old way, with dstadr shown rather than refid [IP version]" },
160 { "lopeers", lopeers, { OPT|IP_VERSION, NO, NO, NO }, 160 { "lopeers", lopeers, { OPT|IP_VERSION, NO, NO, NO },
161 { "-4|-6", "", "", "" }, 161 { "-4|-6", "", "", "" },
162 "obtain and print a list of all peers and clients showing dstadr [IP version]" }, 162 "obtain and print a list of all peers and clients showing dstadr [IP version]" },
163 { ":config", config, { NTP_STR, NO, NO, NO }, 163 { ":config", config, { NTP_STR, NO, NO, NO },
164 { "<configuration command line>", "", "", "" }, 164 { "<configuration command line>", "", "", "" },
165 "send a remote configuration command to ntpd" }, 165 "send a remote configuration command to ntpd" },
166 { "config-from-file", config_from_file, { NTP_STR, NO, NO, NO }, 166 { "config-from-file", config_from_file, { NTP_STR, NO, NO, NO },
167 { "<configuration filename>", "", "", "" }, 167 { "<configuration filename>", "", "", "" },
168 "configure ntpd using the configuration filename" }, 168 "configure ntpd using the configuration filename" },
169 { 0, 0, { NO, NO, NO, NO }, 169 { 0, 0, { NO, NO, NO, NO },
170 { "-4|-6", "", "", "" }, "" } 170 { "-4|-6", "", "", "" }, "" }
171}; 171};
172 172
173 173
174/* 174/*
175 * Variable list data space 175 * Variable list data space
176 */ 176 */
177#define MAXLINE 512 /* maximum length of a line */ 177#define MAXLINE 512 /* maximum length of a line */
178#define MAXLIST 64 /* maximum number of variables in list */ 178#define MAXLIST 64 /* maximum number of variables in list */
179#define LENHOSTNAME 256 /* host name is 256 characters long */ 179#define LENHOSTNAME 256 /* host name is 256 characters long */
180/* 180/*
181 * Old CTL_PST defines for version 2. 181 * Old CTL_PST defines for version 2.
182 */ 182 */
183#define OLD_CTL_PST_CONFIG 0x80 183#define OLD_CTL_PST_CONFIG 0x80
184#define OLD_CTL_PST_AUTHENABLE 0x40 184#define OLD_CTL_PST_AUTHENABLE 0x40
185#define OLD_CTL_PST_AUTHENTIC 0x20 185#define OLD_CTL_PST_AUTHENTIC 0x20
186#define OLD_CTL_PST_REACH 0x10 186#define OLD_CTL_PST_REACH 0x10
187#define OLD_CTL_PST_SANE 0x08 187#define OLD_CTL_PST_SANE 0x08
188#define OLD_CTL_PST_DISP 0x04 188#define OLD_CTL_PST_DISP 0x04
189 189
190#define OLD_CTL_PST_SEL_REJECT 0 190#define OLD_CTL_PST_SEL_REJECT 0
191#define OLD_CTL_PST_SEL_SELCAND 1 191#define OLD_CTL_PST_SEL_SELCAND 1
192#define OLD_CTL_PST_SEL_SYNCCAND 2 192#define OLD_CTL_PST_SEL_SYNCCAND 2
193#define OLD_CTL_PST_SEL_SYSPEER 3 193#define OLD_CTL_PST_SEL_SYSPEER 3
194 194
195char flash2[] = " .+* "; /* flash decode for version 2 */ 195char flash2[] = " .+* "; /* flash decode for version 2 */
196char flash3[] = " x.-+#*o"; /* flash decode for peer status version 3 */ 196char flash3[] = " x.-+#*o"; /* flash decode for peer status version 3 */
197 197
198struct varlist { 198struct varlist {
199 char *name; 199 char *name;
200 char *value; 200 char *value;
201} g_varlist[MAXLIST] = { { 0, 0 } }; 201} g_varlist[MAXLIST] = { { 0, 0 } };
202 202
203/* 203/*
204 * Imported from ntpq.c 204 * Imported from ntpq.c
205 */ 205 */
206extern int showhostnames; 206extern int showhostnames;
207extern int rawmode; 207extern int rawmode;
208extern struct servent *server_entry; 208extern struct servent *server_entry;
209extern struct association assoc_cache[]; 209extern struct association assoc_cache[];
210extern int numassoc; 210extern int numassoc;
211extern u_char pktversion; 211extern u_char pktversion;
212extern struct ctl_var peer_var[]; 212extern struct ctl_var peer_var[];
213 213
214/* 214/*
215 * For quick string comparisons 215 * For quick string comparisons
216 */ 216 */
217#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0) 217#define STREQ(a, b) (*(a) == *(b) && strcmp((a), (b)) == 0)
218 218
219 219
220/* 220/*
221 * checkassocid - return the association ID, checking to see if it is valid 221 * checkassocid - return the association ID, checking to see if it is valid
222 */ 222 */
223static int 223static int
224checkassocid( 224checkassocid(
225 u_int32 value 225 u_int32 value
226 ) 226 )
227{ 227{
228 if (value == 0 || value >= 65536) { 228 if (value == 0 || value >= 65536) {
229 (void) fprintf(stderr, "***Invalid association ID specified\n"); 229 (void) fprintf(stderr, "***Invalid association ID specified\n");
230 return 0; 230 return 0;
231 } 231 }
232 return (int)value; 232 return (int)value;
233} 233}
234 234
235 235
236/* 236/*
237 * findlistvar - look for the named variable in a list and return if found 237 * findlistvar - look for the named variable in a list and return if found
238 */ 238 */
239static struct varlist * 239static struct varlist *
240findlistvar( 240findlistvar(
241 struct varlist *list, 241 struct varlist *list,
242 char *name 242 char *name
243 ) 243 )
244{ 244{
245 register struct varlist *vl; 245 register struct varlist *vl;
246 246
247 for (vl = list; vl < list + MAXLIST && vl->name != 0; vl++) 247 for (vl = list; vl < list + MAXLIST && vl->name != 0; vl++)
248 if (STREQ(name, vl->name)) 248 if (STREQ(name, vl->name))
249 return vl; 249 return vl;
250 if (vl < list + MAXLIST) 250 if (vl < list + MAXLIST)
251 return vl; 251 return vl;
252 return (struct varlist *)0; 252 return (struct varlist *)0;
253} 253}
254 254
255 255
256/* 256/*
257 * doaddvlist - add variable(s) to the variable list 257 * doaddvlist - add variable(s) to the variable list
258 */ 258 */
259static void 259static void
260doaddvlist( 260doaddvlist(
261 struct varlist *vlist, 261 struct varlist *vlist,
262 char *vars 262 char *vars
263 ) 263 )
264{ 264{
265 register struct varlist *vl; 265 register struct varlist *vl;
266 int len; 266 int len;
267 char *name; 267 char *name;
268 char *value; 268 char *value;
269 269
270 len = strlen(vars); 270 len = strlen(vars);
271 while (nextvar(&len, &vars, &name, &value)) { 271 while (nextvar(&len, &vars, &name, &value)) {
272 vl = findlistvar(vlist, name); 272 vl = findlistvar(vlist, name);
273 if (vl == 0) { 273 if (vl == 0) {
274 (void) fprintf(stderr, "Variable list full\n"); 274 (void) fprintf(stderr, "Variable list full\n");
275 return; 275 return;
276 } 276 }
277 277
278 if (vl->name == 0) { 278 if (vl->name == 0) {
279 vl->name = estrdup(name); 279 vl->name = estrdup(name);
280 } else if (vl->value != 0) { 280 } else if (vl->value != 0) {
281 free(vl->value); 281 free(vl->value);
282 vl->value = 0; 282 vl->value = 0;
283 } 283 }
284 284
285 if (value != 0) 285 if (value != 0)
286 vl->value = estrdup(value); 286 vl->value = estrdup(value);
287 } 287 }
288} 288}
289 289
290 290
291/* 291/*
292 * dormvlist - remove variable(s) from the variable list 292 * dormvlist - remove variable(s) from the variable list
293 */ 293 */
294static void 294static void
295dormvlist( 295dormvlist(
296 struct varlist *vlist, 296 struct varlist *vlist,
297 char *vars 297 char *vars
298 ) 298 )
299{ 299{
300 register struct varlist *vl; 300 register struct varlist *vl;
301 int len; 301 int len;
302 char *name; 302 char *name;
303 char *value; 303 char *value;
304 304
305 len = strlen(vars); 305 len = strlen(vars);
306 while (nextvar(&len, &vars, &name, &value)) { 306 while (nextvar(&len, &vars, &name, &value)) {
307 vl = findlistvar(vlist, name); 307 vl = findlistvar(vlist, name);
308 if (vl == 0 || vl->name == 0) { 308 if (vl == 0 || vl->name == 0) {
309 (void) fprintf(stderr, "Variable `%s' not found\n", 309 (void) fprintf(stderr, "Variable `%s' not found\n",
310 name); 310 name);
311 } else { 311 } else {
312 free((void *)vl->name); 312 free((void *)vl->name);
313 if (vl->value != 0) 313 if (vl->value != 0)
314 free(vl->value); 314 free(vl->value);
315 for ( ; (vl+1) < (g_varlist + MAXLIST) 315 for ( ; (vl+1) < (g_varlist + MAXLIST)
316 && (vl+1)->name != 0; vl++) { 316 && (vl+1)->name != 0; vl++) {
317 vl->name = (vl+1)->name; 317 vl->name = (vl+1)->name;
318 vl->value = (vl+1)->value; 318 vl->value = (vl+1)->value;
319 } 319 }
320 vl->name = vl->value = 0; 320 vl->name = vl->value = 0;
321 } 321 }
322 } 322 }
323} 323}
324 324
325 325
326/* 326/*
327 * doclearvlist - clear a variable list 327 * doclearvlist - clear a variable list
328 */ 328 */
329static void 329static void
330doclearvlist( 330doclearvlist(
331 struct varlist *vlist 331 struct varlist *vlist
332 ) 332 )
333{ 333{
334 register struct varlist *vl; 334 register struct varlist *vl;
335 335
336 for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) { 336 for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) {
337 free((void *)vl->name); 337 free((void *)vl->name);
338 vl->name = 0; 338 vl->name = 0;
339 if (vl->value != 0) { 339 if (vl->value != 0) {
340 free(vl->value); 340 free(vl->value);
341 vl->value = 0; 341 vl->value = 0;
342 } 342 }
343 } 343 }
344} 344}
345 345
346 346
347/* 347/*
348 * makequerydata - form a data buffer to be included with a query 348 * makequerydata - form a data buffer to be included with a query
349 */ 349 */
350static void 350static void
351makequerydata( 351makequerydata(
352 struct varlist *vlist, 352 struct varlist *vlist,
353 int *datalen, 353 int *datalen,
354 char *data 354 char *data
355 ) 355 )
356{ 356{
357 register struct varlist *vl; 357 register struct varlist *vl;
358 register char *cp, *cpend; 358 register char *cp, *cpend;
359 register int namelen, valuelen; 359 register int namelen, valuelen;
360 register int totallen; 360 register int totallen;
361 361
362 cp = data; 362 cp = data;
363 cpend = data + *datalen; 363 cpend = data + *datalen;
364 364
365 for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) { 365 for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) {
366 namelen = strlen(vl->name); 366 namelen = strlen(vl->name);
367 if (vl->value == 0) 367 if (vl->value == 0)
368 valuelen = 0; 368 valuelen = 0;
369 else 369 else
370 valuelen = strlen(vl->value); 370 valuelen = strlen(vl->value);
371 totallen = namelen + valuelen + (valuelen != 0) + (cp != data); 371 totallen = namelen + valuelen + (valuelen != 0) + (cp != data);
372 if (cp + totallen > cpend) 372 if (cp + totallen > cpend)
373 break; 373 break;
374 374
375 if (cp != data) 375 if (cp != data)
376 *cp++ = ','; 376 *cp++ = ',';
377 memmove(cp, vl->name, (unsigned)namelen); 377 memmove(cp, vl->name, (unsigned)namelen);
378 cp += namelen; 378 cp += namelen;
379 if (valuelen != 0) { 379 if (valuelen != 0) {
380 *cp++ = '='; 380 *cp++ = '=';
381 memmove(cp, vl->value, (unsigned)valuelen); 381 memmove(cp, vl->value, (unsigned)valuelen);
382 cp += valuelen; 382 cp += valuelen;
383 } 383 }
384 } 384 }
385 *datalen = cp - data; 385 *datalen = cp - data;
386} 386}
387 387
388 388
389/* 389/*
390 * doquerylist - send a message including variables in a list 390 * doquerylist - send a message including variables in a list
391 */ 391 */
392static int 392static int
393doquerylist( 393doquerylist(
394 struct varlist *vlist, 394 struct varlist *vlist,
395 int op, 395 int op,
396 int associd, 396 int associd,
397 int auth, 397 int auth,
398 u_short *rstatus, 398 u_short *rstatus,
399 int *dsize, 399 int *dsize,
400 char **datap 400 char **datap
401 ) 401 )
402{ 402{
403 char data[CTL_MAX_DATA_LEN]; 403 char data[CTL_MAX_DATA_LEN];
404 int datalen; 404 int datalen;
405 405
406 datalen = sizeof(data); 406 datalen = sizeof(data);
407 makequerydata(vlist, &datalen, data); 407 makequerydata(vlist, &datalen, data);
408 408
409 return doquery(op, associd, auth, datalen, data, rstatus, 409 return doquery(op, associd, auth, datalen, data, rstatus,
410 dsize, datap); 410 dsize, datap);
411} 411}
412 412
413 413
414/* 414/*
415 * doprintvlist - print the variables on a list 415 * doprintvlist - print the variables on a list
416 */ 416 */
417static void 417static void
418doprintvlist( 418doprintvlist(
419 struct varlist *vlist, 419 struct varlist *vlist,
420 FILE *fp 420 FILE *fp
421 ) 421 )
422{ 422{
423 register struct varlist *vl; 423 register struct varlist *vl;
424 424
425 if (vlist->name == 0) { 425 if (vlist->name == 0) {
426 (void) fprintf(fp, "No variables on list\n"); 426 (void) fprintf(fp, "No variables on list\n");
427 } else { 427 } else {
428 for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) { 428 for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) {
429 if (vl->value == 0) { 429 if (vl->value == 0) {
430 (void) fprintf(fp, "%s\n", vl->name); 430 (void) fprintf(fp, "%s\n", vl->name);
431 } else { 431 } else {
432 (void) fprintf(fp, "%s=%s\n", 432 (void) fprintf(fp, "%s=%s\n",
433 vl->name, vl->value); 433 vl->name, vl->value);
434 } 434 }
435 } 435 }
436 } 436 }
437} 437}
438 438
439/* 439/*
440 * addvars - add variables to the variable list 440 * addvars - add variables to the variable list
441 */ 441 */
442/*ARGSUSED*/ 442/*ARGSUSED*/
443static void 443static void
444addvars( 444addvars(
445 struct parse *pcmd, 445 struct parse *pcmd,
446 FILE *fp 446 FILE *fp
447 ) 447 )
448{ 448{
449 doaddvlist(g_varlist, pcmd->argval[0].string); 449 doaddvlist(g_varlist, pcmd->argval[0].string);
450} 450}
451 451
452 452
453/* 453/*
454 * rmvars - remove variables from the variable list 454 * rmvars - remove variables from the variable list
455 */ 455 */
456/*ARGSUSED*/ 456/*ARGSUSED*/
457static void 457static void
458rmvars( 458rmvars(
459 struct parse *pcmd, 459 struct parse *pcmd,
460 FILE *fp 460 FILE *fp
461 ) 461 )
462{ 462{
463 dormvlist(g_varlist, pcmd->argval[0].string); 463 dormvlist(g_varlist, pcmd->argval[0].string);
464} 464}
465 465
466 466
467/* 467/*
468 * clearvars - clear the variable list 468 * clearvars - clear the variable list
469 */ 469 */
470/*ARGSUSED*/ 470/*ARGSUSED*/
471static void 471static void
472clearvars( 472clearvars(
473 struct parse *pcmd, 473 struct parse *pcmd,
474 FILE *fp 474 FILE *fp
475 ) 475 )
476{ 476{
477 doclearvlist(g_varlist); 477 doclearvlist(g_varlist);
478} 478}
479 479
480 480
481/* 481/*
482 * showvars - show variables on the variable list 482 * showvars - show variables on the variable list
483 */ 483 */
484/*ARGSUSED*/ 484/*ARGSUSED*/
485static void 485static void
486showvars( 486showvars(
487 struct parse *pcmd, 487 struct parse *pcmd,
488 FILE *fp 488 FILE *fp
489 ) 489 )
490{ 490{
491 doprintvlist(g_varlist, fp); 491 doprintvlist(g_varlist, fp);
492} 492}
493 493
494 494
495/* 495/*
496 * dolist - send a request with the given list of variables 496 * dolist - send a request with the given list of variables
497 */ 497 */
498static int 498static int
499dolist( 499dolist(
500 struct varlist *vlist, 500 struct varlist *vlist,
501 int associd, 501 int associd,
502 int op, 502 int op,
503 int type, 503 int type,
504 FILE *fp 504 FILE *fp
505 ) 505 )
506{ 506{
507 char *datap; 507 char *datap;
508 int res; 508 int res;
509 int dsize; 509 int dsize;
510 u_short rstatus; 510 u_short rstatus;
511 int quiet; 511 int quiet;
512 512
513 /* 513 /*
514 * if we're asking for specific variables don't include the 514 * if we're asking for specific variables don't include the
515 * status header line in the output. 515 * status header line in the output.
516 */ 516 */
517 if (old_rv) 517 if (old_rv)
518 quiet = 0; 518 quiet = 0;
519 else 519 else
520 quiet = (vlist->name != NULL); 520 quiet = (vlist->name != NULL);
521 521
522 res = doquerylist(vlist, op, associd, 0, &rstatus, &dsize, &datap); 522 res = doquerylist(vlist, op, associd, 0, &rstatus, &dsize, &datap);
523 523
524 if (res != 0) 524 if (res != 0)
525 return 0; 525 return 0;
526 526
527 if (numhosts > 1) 527 if (numhosts > 1)
528 (void) fprintf(fp, "server=%s ", currenthost); 528 (void) fprintf(fp, "server=%s ", currenthost);
529 if (dsize == 0) { 529 if (dsize == 0) {
530 if (associd == 0) 530 if (associd == 0)
531 (void) fprintf(fp, "No system%s variables returned\n", 531 (void) fprintf(fp, "No system%s variables returned\n",
532 (type == TYPE_CLOCK) ? " clock" : ""); 532 (type == TYPE_CLOCK) ? " clock" : "");
533 else 533 else
534 (void) fprintf(fp, 534 (void) fprintf(fp,
535 "No information returned for%s association %u\n", 535 "No information returned for%s association %u\n",
536 (type == TYPE_CLOCK) ? " clock" : "", associd); 536 (type == TYPE_CLOCK) ? " clock" : "", associd);
537 return 1; 537 return 1;
538 } 538 }
539 539
540 if (!quiet) 540 if (!quiet)
541 fprintf(fp,"associd=%d ",associd); 541 fprintf(fp,"associd=%d ",associd);
542 printvars(dsize, datap, (int)rstatus, type, quiet, fp); 542 printvars(dsize, datap, (int)rstatus, type, quiet, fp);
543 return 1; 543 return 1;
544} 544}
545 545
546 546
547/* 547/*
548 * readlist - send a read variables request with the variables on the list 548 * readlist - send a read variables request with the variables on the list
549 */ 549 */
550static void 550static void
551readlist( 551readlist(
552 struct parse *pcmd, 552 struct parse *pcmd,
553 FILE *fp 553 FILE *fp
554 ) 554 )
555{ 555{
556 int associd; 556 int associd;
557 557
558 if (pcmd->nargs == 0) { 558 if (pcmd->nargs == 0) {
559 associd = 0; 559 associd = 0;
560 } else { 560 } else {
561 /* HMS: I think we want the u_int32 target here, not the u_long */ 561 /* HMS: I think we want the u_int32 target here, not the u_long */
562 if (pcmd->argval[0].uval == 0) 562 if (pcmd->argval[0].uval == 0)
563 associd = 0; 563 associd = 0;
564 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) 564 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
565 return; 565 return;
566 } 566 }
567 567
568 (void) dolist(g_varlist, associd, CTL_OP_READVAR, 568 (void) dolist(g_varlist, associd, CTL_OP_READVAR,
569 (associd == 0) ? TYPE_SYS : TYPE_PEER, fp); 569 (associd == 0) ? TYPE_SYS : TYPE_PEER, fp);
570} 570}
571 571
572 572
573/* 573/*
574 * writelist - send a write variables request with the variables on the list 574 * writelist - send a write variables request with the variables on the list
575 */ 575 */
576static void 576static void
577writelist( 577writelist(
578 struct parse *pcmd, 578 struct parse *pcmd,
579 FILE *fp 579 FILE *fp
580 ) 580 )
581{ 581{
582 char *datap; 582 char *datap;
583 int res; 583 int res;
584 int associd; 584 int associd;
585 int dsize; 585 int dsize;
586 u_short rstatus; 586 u_short rstatus;
587 587
588 if (pcmd->nargs == 0) { 588 if (pcmd->nargs == 0) {
589 associd = 0; 589 associd = 0;
590 } else { 590 } else {
591 /* HMS: Do we really want uval here? */ 591 /* HMS: Do we really want uval here? */
592 if (pcmd->argval[0].uval == 0) 592 if (pcmd->argval[0].uval == 0)
593 associd = 0; 593 associd = 0;
594 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) 594 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
595 return; 595 return;
596 } 596 }
597 597
598 res = doquerylist(g_varlist, CTL_OP_WRITEVAR, associd, 1, &rstatus, 598 res = doquerylist(g_varlist, CTL_OP_WRITEVAR, associd, 1, &rstatus,
599 &dsize, &datap); 599 &dsize, &datap);
600 600
601 if (res != 0) 601 if (res != 0)
602 return; 602 return;
603 603
604 if (numhosts > 1) 604 if (numhosts > 1)
605 (void) fprintf(fp, "server=%s ", currenthost); 605 (void) fprintf(fp, "server=%s ", currenthost);
606 if (dsize == 0) 606 if (dsize == 0)
607 (void) fprintf(fp, "done! (no data returned)\n"); 607 (void) fprintf(fp, "done! (no data returned)\n");
608 else { 608 else {
609 (void) fprintf(fp,"associd=%d ",associd); 609 (void) fprintf(fp,"associd=%d ",associd);
610 printvars(dsize, datap, (int)rstatus, 610 printvars(dsize, datap, (int)rstatus,
611 (associd != 0) ? TYPE_PEER : TYPE_SYS, 0, fp); 611 (associd != 0) ? TYPE_PEER : TYPE_SYS, 0, fp);
612 } 612 }
613 return; 613 return;
614} 614}
615 615
616 616
617/* 617/*
618 * readvar - send a read variables request with the specified variables 618 * readvar - send a read variables request with the specified variables
619 */ 619 */
620static void 620static void
621readvar( 621readvar(
622 struct parse *pcmd, 622 struct parse *pcmd,
623 FILE *fp 623 FILE *fp
624 ) 624 )
625{ 625{
626 int associd; 626 int associd;
627 struct varlist tmplist[MAXLIST]; 627 struct varlist tmplist[MAXLIST];
628 628
629 /* HMS: uval? */ 629 /* HMS: uval? */
630 if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0) 630 if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0)
631 associd = 0; 631 associd = 0;
632 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) 632 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
633 return; 633 return;
634 634
635 memset((char *)tmplist, 0, sizeof(tmplist)); 635 memset((char *)tmplist, 0, sizeof(tmplist));
636 if (pcmd->nargs >= 2) 636 if (pcmd->nargs >= 2)
637 doaddvlist(tmplist, pcmd->argval[1].string); 637 doaddvlist(tmplist, pcmd->argval[1].string);
638 638
639 (void) dolist(tmplist, associd, CTL_OP_READVAR, 639 (void) dolist(tmplist, associd, CTL_OP_READVAR,
640 (associd == 0) ? TYPE_SYS : TYPE_PEER, fp); 640 (associd == 0) ? TYPE_SYS : TYPE_PEER, fp);
641 641
642 doclearvlist(tmplist); 642 doclearvlist(tmplist);
643} 643}
644 644
645 645
646/* 646/*
647 * writevar - send a write variables request with the specified variables 647 * writevar - send a write variables request with the specified variables
648 */ 648 */
649static void 649static void
650writevar( 650writevar(
651 struct parse *pcmd, 651 struct parse *pcmd,
652 FILE *fp 652 FILE *fp
653 ) 653 )
654{ 654{
655 char *datap; 655 char *datap;
656 int res; 656 int res;
657 int associd; 657 int associd;
658 int dsize; 658 int dsize;
659 u_short rstatus; 659 u_short rstatus;
660 struct varlist tmplist[MAXLIST]; 660 struct varlist tmplist[MAXLIST];
661 661
662 /* HMS: uval? */ 662 /* HMS: uval? */
663 if (pcmd->argval[0].uval == 0) 663 if (pcmd->argval[0].uval == 0)
664 associd = 0; 664 associd = 0;
665 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) 665 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
666 return; 666 return;
667 667
668 memset((char *)tmplist, 0, sizeof(tmplist)); 668 memset((char *)tmplist, 0, sizeof(tmplist));
669 doaddvlist(tmplist, pcmd->argval[1].string); 669 doaddvlist(tmplist, pcmd->argval[1].string);
670 670
671 res = doquerylist(tmplist, CTL_OP_WRITEVAR, associd, 1, &rstatus, 671 res = doquerylist(tmplist, CTL_OP_WRITEVAR, associd, 1, &rstatus,
672 &dsize, &datap); 672 &dsize, &datap);
673 673
674 doclearvlist(tmplist); 674 doclearvlist(tmplist);
675 675
676 if (res != 0) 676 if (res != 0)
677 return; 677 return;
678 678
679 if (numhosts > 1) 679 if (numhosts > 1)
680 (void) fprintf(fp, "server=%s ", currenthost); 680 (void) fprintf(fp, "server=%s ", currenthost);
681 if (dsize == 0) 681 if (dsize == 0)
682 (void) fprintf(fp, "done! (no data returned)\n"); 682 (void) fprintf(fp, "done! (no data returned)\n");
683 else { 683 else {
684 (void) fprintf(fp,"associd=%d ",associd); 684 (void) fprintf(fp,"associd=%d ",associd);
685 printvars(dsize, datap, (int)rstatus, 685 printvars(dsize, datap, (int)rstatus,
686 (associd != 0) 686 (associd != 0)
687 ? TYPE_PEER  687 ? TYPE_PEER
688 : TYPE_SYS,  688 : TYPE_SYS,
689 0, fp); 689 0, fp);
690 } 690 }
691 return; 691 return;
692} 692}
693 693
694 694
695/* 695/*
696 * clocklist - send a clock variables request with the variables on the list 696 * clocklist - send a clock variables request with the variables on the list
697 */ 697 */
698static void 698static void
699clocklist( 699clocklist(
700 struct parse *pcmd, 700 struct parse *pcmd,
701 FILE *fp 701 FILE *fp
702 ) 702 )
703{ 703{
704 int associd; 704 int associd;
705 705
706 /* HMS: uval? */ 706 /* HMS: uval? */
707 if (pcmd->nargs == 0) { 707 if (pcmd->nargs == 0) {
708 associd = 0; 708 associd = 0;
709 } else { 709 } else {
710 if (pcmd->argval[0].uval == 0) 710 if (pcmd->argval[0].uval == 0)
711 associd = 0; 711 associd = 0;
712 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) 712 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
713 return; 713 return;
714 } 714 }
715 715
716 (void) dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp); 716 (void) dolist(g_varlist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
717} 717}
718 718
719 719
720/* 720/*
721 * clockvar - send a clock variables request with the specified variables 721 * clockvar - send a clock variables request with the specified variables
722 */ 722 */
723static void 723static void
724clockvar( 724clockvar(
725 struct parse *pcmd, 725 struct parse *pcmd,
726 FILE *fp 726 FILE *fp
727 ) 727 )
728{ 728{
729 int associd; 729 int associd;
730 struct varlist tmplist[MAXLIST]; 730 struct varlist tmplist[MAXLIST];
731 731
732 /* HMS: uval? */ 732 /* HMS: uval? */
733 if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0) 733 if (pcmd->nargs == 0 || pcmd->argval[0].uval == 0)
734 associd = 0; 734 associd = 0;
735 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0) 735 else if ((associd = checkassocid(pcmd->argval[0].uval)) == 0)
736 return; 736 return;
737 737
738 memset((char *)tmplist, 0, sizeof(tmplist)); 738 memset((char *)tmplist, 0, sizeof(tmplist));
739 if (pcmd->nargs >= 2) 739 if (pcmd->nargs >= 2)
740 doaddvlist(tmplist, pcmd->argval[1].string); 740 doaddvlist(tmplist, pcmd->argval[1].string);
741 741
742 (void) dolist(tmplist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp); 742 (void) dolist(tmplist, associd, CTL_OP_READCLOCK, TYPE_CLOCK, fp);
743 743
744 doclearvlist(tmplist); 744 doclearvlist(tmplist);
745} 745}
746 746
747 747
748/* 748/*
749 * findassidrange - verify a range of association ID's 749 * findassidrange - verify a range of association ID's
750 */ 750 */
751static int 751static int
752findassidrange( 752findassidrange(
753 u_int32 assid1, 753 u_int32 assid1,
754 u_int32 assid2, 754 u_int32 assid2,
755 int *from, 755 int *from,
756 int *to 756 int *to
757 ) 757 )
758{ 758{
759 register int i; 759 register int i;
760 int f, t; 760 int f, t;
761 761
762 if (assid1 == 0 || assid1 > 65535) { 762 if (assid1 == 0 || assid1 > 65535) {
763 (void) fprintf(stderr, 763 (void) fprintf(stderr,
764 "***Invalid association ID %lu specified\n", (u_long)assid1); 764 "***Invalid association ID %lu specified\n", (u_long)assid1);
765 return 0; 765 return 0;
766 } 766 }
767 767
768 if (assid2 == 0 || assid2 > 65535) { 768 if (assid2 == 0 || assid2 > 65535) {
769 fprintf(stderr, 769 fprintf(stderr,
770 "***Invalid association ID %lu specified\n", (u_long)assid2); 770 "***Invalid association ID %lu specified\n", (u_long)assid2);
771 return 0; 771 return 0;
772 } 772 }
773 773
774 f = t = -1; 774 f = t = -1;
775 for (i = 0; i < numassoc; i++) { 775 for (i = 0; i < numassoc; i++) {
776 if (assoc_cache[i].assid == assid1) { 776 if (assoc_cache[i].assid == assid1) {
777 f = i; 777 f = i;
778 if (t != -1) 778 if (t != -1)
779 break; 779 break;
780 } 780 }
781 if (assoc_cache[i].assid == assid2) { 781 if (assoc_cache[i].assid == assid2) {
782 t = i; 782 t = i;
783 if (f != -1) 783 if (f != -1)
784 break; 784 break;
785 } 785 }
786 } 786 }
787 787
788 if (f == -1 || t == -1) { 788 if (f == -1 || t == -1) {
789 (void) fprintf(stderr, 789 (void) fprintf(stderr,
790 "***Association ID %lu not found in list\n", 790 "***Association ID %lu not found in list\n",
791 (f == -1) ? (u_long)assid1 : (u_long)assid2); 791 (f == -1) ? (u_long)assid1 : (u_long)assid2);
792 return 0; 792 return 0;
793 } 793 }
794 794
795 if (f < t) { 795 if (f < t) {
796 *from = f; 796 *from = f;
797 *to = t; 797 *to = t;
798 } else { 798 } else {
799 *from = t; 799 *from = t;
800 *to = f; 800 *to = f;
801 } 801 }
802 return 1; 802 return 1;
803} 803}
804 804
805 805
806 806
807/* 807/*
808 * mreadlist - send a read variables request for multiple associations 808 * mreadlist - send a read variables request for multiple associations
809 */ 809 */
810static void 810static void
811mreadlist( 811mreadlist(
812 struct parse *pcmd, 812 struct parse *pcmd,
813 FILE *fp 813 FILE *fp
814 ) 814 )
815{ 815{
816 int i; 816 int i;
817 int from; 817 int from;
818 int to; 818 int to;
819 819
820 /* HMS: uval? */ 820 /* HMS: uval? */
821 if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval, 821 if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval,
822 &from, &to)) 822 &from, &to))
823 return; 823 return;
824 824
825 for (i = from; i <= to; i++) { 825 for (i = from; i <= to; i++) {
826 if (i != from) 826 if (i != from)
827 (void) fprintf(fp, "\n"); 827 (void) fprintf(fp, "\n");
828 if (!dolist(g_varlist, (int)assoc_cache[i].assid, 828 if (!dolist(g_varlist, (int)assoc_cache[i].assid,
829 CTL_OP_READVAR, TYPE_PEER, fp)) 829 CTL_OP_READVAR, TYPE_PEER, fp))
830 return; 830 return;
831 } 831 }
832 return; 832 return;
833} 833}
834 834
835 835
836/* 836/*
837 * mreadvar - send a read variables request for multiple associations 837 * mreadvar - send a read variables request for multiple associations
838 */ 838 */
839static void 839static void
840mreadvar( 840mreadvar(
841 struct parse *pcmd, 841 struct parse *pcmd,
842 FILE *fp 842 FILE *fp
843 ) 843 )
844{ 844{
845 int i; 845 int i;
846 int from; 846 int from;
847 int to; 847 int to;
848 struct varlist tmplist[MAXLIST]; 848 struct varlist tmplist[MAXLIST];
849 849
850 /* HMS: uval? */ 850 /* HMS: uval? */
851 if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval, 851 if (!findassidrange(pcmd->argval[0].uval, pcmd->argval[1].uval,
852 &from, &to)) 852 &from, &to))
853 return; 853 return;
854 854
855 memset((char *)tmplist, 0, sizeof(tmplist)); 855 memset((char *)tmplist, 0, sizeof(tmplist));
856 if (pcmd->nargs >= 3) 856 if (pcmd->nargs >= 3)
857 doaddvlist(tmplist, pcmd->argval[2].string); 857 doaddvlist(tmplist, pcmd->argval[2].string);
858 858
859 for (i = from; i <= to; i++) { 859 for (i = from; i <= to; i++) {
860 if (i != from) 860 if (i != from)
861 (void) fprintf(fp, "\n"); 861 (void) fprintf(fp, "\n");
862 if (!dolist(g_varlist, (int)assoc_cache[i].assid, 862 if (!dolist(g_varlist, (int)assoc_cache[i].assid,
863 CTL_OP_READVAR, TYPE_PEER, fp)) 863 CTL_OP_READVAR, TYPE_PEER, fp))
864 break; 864 break;
865 } 865 }
866 doclearvlist(tmplist); 866 doclearvlist(tmplist);
867 return; 867 return;
868} 868}
869 869
870 870
871/* 871/*
872 * dogetassoc - query the host for its list of associations 872 * dogetassoc - query the host for its list of associations
873 */ 873 */
874static int 874static int
875dogetassoc( 875dogetassoc(
876 FILE *fp 876 FILE *fp
877 ) 877 )
878{ 878{
879 char *datap; 879 char *datap;
880 int res; 880 int res;
881 int dsize; 881 int dsize;
882 u_short rstatus; 882 u_short rstatus;
883 883
884 res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus, 884 res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus,
885 &dsize, &datap); 885 &dsize, &datap);
886 886
887 if (res != 0) 887 if (res != 0)
888 return 0; 888 return 0;
889 889
890 if (dsize == 0) { 890 if (dsize == 0) {
891 if (numhosts > 1) 891 if (numhosts > 1)
892 (void) fprintf(fp, "server=%s ", currenthost); 892 (void) fprintf(fp, "server=%s ", currenthost);
893 (void) fprintf(fp, "No association ID's returned\n"); 893 (void) fprintf(fp, "No association ID's returned\n");
894 return 0; 894 return 0;
895 } 895 }
896 896
897 if (dsize & 0x3) { 897 if (dsize & 0x3) {
898 if (numhosts > 1) 898 if (numhosts > 1)
899 (void) fprintf(stderr, "server=%s ", currenthost); 899 (void) fprintf(stderr, "server=%s ", currenthost);
900 (void) fprintf(stderr, 900 (void) fprintf(stderr,
901 "***Server returned %d octets, should be multiple of 4\n", 901 "***Server returned %d octets, should be multiple of 4\n",
902 dsize); 902 dsize);
903 return 0; 903 return 0;
904 } 904 }
905 905
906 numassoc = 0; 906 numassoc = 0;
907 while (dsize > 0) { 907 while (dsize > 0) {
908 assoc_cache[numassoc].assid = ntohs(*((u_short *)datap)); 908 assoc_cache[numassoc].assid = ntohs(*((u_short *)datap));
909 datap += sizeof(u_short); 909 datap += sizeof(u_short);
910 assoc_cache[numassoc].status = ntohs(*((u_short *)datap)); 910 assoc_cache[numassoc].status = ntohs(*((u_short *)datap));
911 datap += sizeof(u_short); 911 datap += sizeof(u_short);
912 if (++numassoc >= MAXASSOC) 912 if (++numassoc >= MAXASSOC)
913 break; 913 break;
914 dsize -= sizeof(u_short) + sizeof(u_short); 914 dsize -= sizeof(u_short) + sizeof(u_short);
915 } 915 }
916 sortassoc(); 916 sortassoc();
917 return 1; 917 return 1;
918} 918}
919 919
920 920
921/* 921/*
922 * printassoc - print the current list of associations 922 * printassoc - print the current list of associations
923 */ 923 */
924static void 924static void
925printassoc( 925printassoc(
926 int showall, 926 int showall,
927 FILE *fp 927 FILE *fp
928 ) 928 )
929{ 929{
930 register char *bp; 930 register char *bp;
931 int i; 931 int i;
932 u_char statval; 932 u_char statval;
933 int event; 933 int event;
934 u_long event_count; 934 u_long event_count;
935 const char *conf; 935 const char *conf;
936 const char *reach; 936 const char *reach;
937 const char *auth; 937 const char *auth;
938 const char *condition = ""; 938 const char *condition = "";
939 const char *last_event; 939 const char *last_event;
940 const char *cnt; 940 const char *cnt;
941 char buf[128]; 941 char buf[128];
942 942
943 if (numassoc == 0) { 943 if (numassoc == 0) {
944 (void) fprintf(fp, "No association ID's in list\n"); 944 (void) fprintf(fp, "No association ID's in list\n");
945 return; 945 return;
946 } 946 }
947 947
948 /* 948 /*
949 * Output a header 949 * Output a header
950 */ 950 */
951 (void) fprintf(fp, 951 (void) fprintf(fp,
952 "\nind assid status conf reach auth condition last_event cnt\n"); 952 "\nind assid status conf reach auth condition last_event cnt\n");
953 (void) fprintf(fp, 953 (void) fprintf(fp,
954 "===========================================================\n"); 954 "===========================================================\n");
955 for (i = 0; i < numassoc; i++) { 955 for (i = 0; i < numassoc; i++) {
956 statval = (u_char) CTL_PEER_STATVAL(assoc_cache[i].status); 956 statval = (u_char) CTL_PEER_STATVAL(assoc_cache[i].status);
957 if (!showall && !(statval & (CTL_PST_CONFIG|CTL_PST_REACH))) 957 if (!showall && !(statval & (CTL_PST_CONFIG|CTL_PST_REACH)))
958 continue; 958 continue;
959 event = CTL_PEER_EVENT(assoc_cache[i].status); 959 event = CTL_PEER_EVENT(assoc_cache[i].status);
960 event_count = CTL_PEER_NEVNT(assoc_cache[i].status); 960 event_count = CTL_PEER_NEVNT(assoc_cache[i].status);
961 if (statval & CTL_PST_CONFIG) 961 if (statval & CTL_PST_CONFIG)
962 conf = "yes"; 962 conf = "yes";
963 else 963 else
964 conf = "no"; 964 conf = "no";
965 if (statval & CTL_PST_BCAST) { 965 if (statval & CTL_PST_BCAST) {
966 reach = "none"; 966 reach = "none";
967 if (statval & CTL_PST_AUTHENABLE) 967 if (statval & CTL_PST_AUTHENABLE)
968 auth = "yes"; 968 auth = "yes";
969 else 969 else
970 auth = "none"; 970 auth = "none";
971 } else { 971 } else {
972 if (statval & CTL_PST_REACH) 972 if (statval & CTL_PST_REACH)
973 reach = "yes"; 973 reach = "yes";
974 else 974 else
975 reach = "no"; 975 reach = "no";
976 if (statval & CTL_PST_AUTHENABLE) { 976 if (statval & CTL_PST_AUTHENABLE) {
977 if (statval & CTL_PST_AUTHENTIC) 977 if (statval & CTL_PST_AUTHENTIC)
978 auth = "ok "; 978 auth = "ok ";
979 else 979 else
980 auth = "bad"; 980 auth = "bad";
981 } else { 981 } else {
982 auth = "none"; 982 auth = "none";
983 } 983 }
984 } 984 }
985 if (pktversion > NTP_OLDVERSION) { 985 if (pktversion > NTP_OLDVERSION) {
986 switch (statval & 0x7) { 986 switch (statval & 0x7) {
987 987
988 case CTL_PST_SEL_REJECT: 988 case CTL_PST_SEL_REJECT:
989 condition = "reject"; 989 condition = "reject";
990 break; 990 break;
991 991
992 case CTL_PST_SEL_SANE: 992 case CTL_PST_SEL_SANE:
993 condition = "falsetick"; 993 condition = "falsetick";
994 break; 994 break;
995 995
996 case CTL_PST_SEL_CORRECT: 996 case CTL_PST_SEL_CORRECT:
997 condition = "excess"; 997 condition = "excess";
998 break; 998 break;
999 999
1000 case CTL_PST_SEL_SELCAND: 1000 case CTL_PST_SEL_SELCAND:
1001 condition = "outlyer"; 1001 condition = "outlyer";
1002 break; 1002 break;
1003 1003
1004 case CTL_PST_SEL_SYNCCAND: 1004 case CTL_PST_SEL_SYNCCAND:
1005 condition = "candidate"; 1005 condition = "candidate";
1006 break; 1006 break;
1007 1007
1008 case CTL_PST_SEL_EXCESS: 1008 case CTL_PST_SEL_EXCESS:
1009 condition = "backup"; 1009 condition = "backup";
1010 break; 1010 break;
1011 1011
1012 case CTL_PST_SEL_SYSPEER: 1012 case CTL_PST_SEL_SYSPEER:
1013 condition = "sys.peer"; 1013 condition = "sys.peer";
1014 break; 1014 break;
1015 1015