statestr.c revision 285612
154359Sroberto/*
254359Sroberto * pretty printing of status information
354359Sroberto */
454359Sroberto#ifdef HAVE_CONFIG_H
554359Sroberto#include <config.h>
654359Sroberto#endif
754359Sroberto#include <stdio.h>
854359Sroberto#include "ntp_stdlib.h"
954359Sroberto#include "ntp_fp.h"
1054359Sroberto#include "ntp.h"
1154359Sroberto#include "lib_strbuf.h"
1254359Sroberto#include "ntp_refclock.h"
1354359Sroberto#include "ntp_control.h"
1454359Sroberto#include "ntp_string.h"
15285612Sdelphij#ifdef KERNEL_PLL
16285612Sdelphij# include "ntp_syscall.h"
17285612Sdelphij#endif
1854359Sroberto
19285612Sdelphij
2054359Sroberto/*
2154359Sroberto * Structure for turning various constants into a readable string.
2254359Sroberto */
2354359Srobertostruct codestring {
2454359Sroberto	int code;
25285612Sdelphij	const char * const string;
2654359Sroberto};
2754359Sroberto
2854359Sroberto/*
29285612Sdelphij * Leap status (leap)
3054359Sroberto */
31285612Sdelphijstatic const struct codestring leap_codes[] = {
3254359Sroberto	{ LEAP_NOWARNING,	"leap_none" },
3354359Sroberto	{ LEAP_ADDSECOND,	"leap_add_sec" },
3454359Sroberto	{ LEAP_DELSECOND,	"leap_del_sec" },
35285612Sdelphij	{ LEAP_NOTINSYNC,	"leap_alarm" },
36285612Sdelphij	{ -1,			"leap" }
3754359Sroberto};
3854359Sroberto
3954359Sroberto/*
40285612Sdelphij * Clock source status (sync)
4154359Sroberto */
42285612Sdelphijstatic const struct codestring sync_codes[] = {
4354359Sroberto	{ CTL_SST_TS_UNSPEC,	"sync_unspec" },
44285612Sdelphij	{ CTL_SST_TS_ATOM,	"sync_pps" },
45285612Sdelphij	{ CTL_SST_TS_LF,	"sync_lf_radio" },
46285612Sdelphij	{ CTL_SST_TS_HF,	"sync_hf_radio" },
47285612Sdelphij	{ CTL_SST_TS_UHF,	"sync_uhf_radio" },
48285612Sdelphij	{ CTL_SST_TS_LOCAL,	"sync_local" },
4954359Sroberto	{ CTL_SST_TS_NTP,	"sync_ntp" },
50285612Sdelphij	{ CTL_SST_TS_UDPTIME,	"sync_other" },
5154359Sroberto	{ CTL_SST_TS_WRSTWTCH,	"sync_wristwatch" },
5254359Sroberto	{ CTL_SST_TS_TELEPHONE,	"sync_telephone" },
5354359Sroberto	{ -1,			"sync" }
5454359Sroberto};
5554359Sroberto
5654359Sroberto/*
57285612Sdelphij * Peer selection status (sel)
5854359Sroberto */
59285612Sdelphijstatic const struct codestring select_codes[] = {
60285612Sdelphij	{ CTL_PST_SEL_REJECT,	"sel_reject" },
6154359Sroberto	{ CTL_PST_SEL_SANE,	"sel_falsetick" },
6254359Sroberto	{ CTL_PST_SEL_CORRECT,	"sel_excess" },
6354359Sroberto	{ CTL_PST_SEL_SELCAND,	"sel_outlyer" },
64285612Sdelphij	{ CTL_PST_SEL_SYNCCAND,	"sel_candidate" },
65285612Sdelphij	{ CTL_PST_SEL_EXCESS,	"sel_backup" },
6654359Sroberto	{ CTL_PST_SEL_SYSPEER,	"sel_sys.peer" },
6754359Sroberto	{ CTL_PST_SEL_PPS,	"sel_pps.peer" },
6854359Sroberto	{ -1,			"sel" }
6954359Sroberto};
7054359Sroberto
7154359Sroberto/*
72285612Sdelphij * Clock status (clk)
7354359Sroberto */
74285612Sdelphijstatic const struct codestring clock_codes[] = {
75285612Sdelphij	{ CTL_CLK_OKAY,		"clk_unspec" },
76285612Sdelphij	{ CTL_CLK_NOREPLY,	"clk_no_reply" },
77285612Sdelphij	{ CTL_CLK_BADFORMAT,	"clk_bad_format" },
7854359Sroberto	{ CTL_CLK_FAULT,	"clk_fault" },
79285612Sdelphij	{ CTL_CLK_PROPAGATION,	"clk_bad_signal" },
80285612Sdelphij	{ CTL_CLK_BADDATE,	"clk_bad_date" },
81285612Sdelphij	{ CTL_CLK_BADTIME,	"clk_bad_time" },
8254359Sroberto	{ -1,			"clk" }
8354359Sroberto};
8454359Sroberto
8554359Sroberto
86285612Sdelphij#ifdef FLASH_CODES_UNUSED
8754359Sroberto/*
88285612Sdelphij * Flash bits -- see ntpq.c tstflags & tstflagnames
8954359Sroberto */
90285612Sdelphijstatic const struct codestring flash_codes[] = {
91285612Sdelphij	{ TEST1,		"pkt_dup" },
92285612Sdelphij	{ TEST2,		"pkt_bogus" },
93285612Sdelphij	{ TEST3,		"pkt_unsync" },
94285612Sdelphij	{ TEST4,		"pkt_denied" },
95285612Sdelphij	{ TEST5,		"pkt_auth" },
96285612Sdelphij	{ TEST6,		"pkt_stratum" },
97285612Sdelphij	{ TEST7,		"pkt_header" },
98285612Sdelphij	{ TEST8,		"pkt_autokey" },
99285612Sdelphij	{ TEST9,		"pkt_crypto" },
100285612Sdelphij	{ TEST10,		"peer_stratum" },
101285612Sdelphij	{ TEST11,		"peer_dist" },
102285612Sdelphij	{ TEST12,		"peer_loop" },
103285612Sdelphij	{ TEST13,		"peer_unreach" },
104285612Sdelphij	{ -1,			"flash" }
10554359Sroberto};
106285612Sdelphij#endif
10754359Sroberto
108285612Sdelphij
10954359Sroberto/*
110285612Sdelphij * System events (sys)
11154359Sroberto */
112285612Sdelphijstatic const struct codestring sys_codes[] = {
113285612Sdelphij	{ EVNT_UNSPEC,		"unspecified" },
114285612Sdelphij	{ EVNT_NSET,		"freq_not_set" },
115285612Sdelphij	{ EVNT_FSET,		"freq_set" },
116285612Sdelphij	{ EVNT_SPIK,		"spike_detect" },
117285612Sdelphij	{ EVNT_FREQ,		"freq_mode" },
118285612Sdelphij	{ EVNT_SYNC,		"clock_sync" },
119285612Sdelphij	{ EVNT_SYSRESTART,	"restart" },
120285612Sdelphij	{ EVNT_SYSFAULT,	"panic_stop" },
121285612Sdelphij	{ EVNT_NOPEER,		"no_sys_peer" },
122285612Sdelphij	{ EVNT_ARMED,		"leap_armed" },
123285612Sdelphij	{ EVNT_DISARMED,	"leap_disarmed" },
124285612Sdelphij	{ EVNT_LEAP,		"leap_event" },
125285612Sdelphij	{ EVNT_CLOCKRESET,	"clock_step" },
126285612Sdelphij	{ EVNT_KERN,		"kern" },
127285612Sdelphij	{ EVNT_TAI,		"TAI" },
128285612Sdelphij	{ EVNT_LEAPVAL,		"stale_leapsecond_values" },
129285612Sdelphij	{ -1,			"" }
13054359Sroberto};
13154359Sroberto
132132451Sroberto/*
133285612Sdelphij * Peer events (peer)
134132451Sroberto */
135285612Sdelphijstatic const struct codestring peer_codes[] = {
136285612Sdelphij	{ PEVNT_MOBIL & ~PEER_EVENT,	"mobilize" },
137285612Sdelphij	{ PEVNT_DEMOBIL & ~PEER_EVENT,	"demobilize" },
138285612Sdelphij	{ PEVNT_UNREACH & ~PEER_EVENT,	"unreachable" },
139285612Sdelphij	{ PEVNT_REACH & ~PEER_EVENT,	"reachable" },
140285612Sdelphij	{ PEVNT_RESTART & ~PEER_EVENT,	"restart" },
141285612Sdelphij	{ PEVNT_REPLY & ~PEER_EVENT,	"no_reply" },
142285612Sdelphij	{ PEVNT_RATE & ~PEER_EVENT,	"rate_exceeded" },
143285612Sdelphij	{ PEVNT_DENY & ~PEER_EVENT,	"access_denied" },
144285612Sdelphij	{ PEVNT_ARMED & ~PEER_EVENT,	"leap_armed" },
145285612Sdelphij	{ PEVNT_NEWPEER & ~PEER_EVENT,	"sys_peer" },
146285612Sdelphij	{ PEVNT_CLOCK & ~PEER_EVENT,	"clock_event" },
147285612Sdelphij	{ PEVNT_AUTH & ~PEER_EVENT,	"bad_auth" },
148285612Sdelphij	{ PEVNT_POPCORN & ~PEER_EVENT,	"popcorn" },
149285612Sdelphij	{ PEVNT_XLEAVE & ~PEER_EVENT,	"interleave_mode" },
150285612Sdelphij	{ PEVNT_XERR & ~PEER_EVENT,	"interleave_error" },
151285612Sdelphij	{ -1,				"" }
152285612Sdelphij};
153285612Sdelphij
154285612Sdelphij/*
155285612Sdelphij * Peer status bits
156285612Sdelphij */
157285612Sdelphijstatic const struct codestring peer_st_bits[] = {
158285612Sdelphij	{ CTL_PST_CONFIG,		"conf" },
159285612Sdelphij	{ CTL_PST_AUTHENABLE,		"authenb" },
160285612Sdelphij	{ CTL_PST_AUTHENTIC,		"auth" },
161285612Sdelphij	{ CTL_PST_REACH,		"reach" },
162285612Sdelphij	{ CTL_PST_BCAST,		"bcast" },
163285612Sdelphij	/* not used with getcode(), no terminating entry needed */
164285612Sdelphij};
165285612Sdelphij
166285612Sdelphij/*
167285612Sdelphij * Restriction match bits
168285612Sdelphij */
169285612Sdelphijstatic const struct codestring res_match_bits[] = {
170285612Sdelphij	{ RESM_NTPONLY,			"ntpport" },
171285612Sdelphij	{ RESM_INTERFACE,		"interface" },
172285612Sdelphij	{ RESM_SOURCE,			"source" },
173285612Sdelphij	/* not used with getcode(), no terminating entry needed */
174285612Sdelphij};
175285612Sdelphij
176285612Sdelphij/*
177285612Sdelphij * Restriction access bits
178285612Sdelphij */
179285612Sdelphijstatic const struct codestring res_access_bits[] = {
180285612Sdelphij	{ RES_IGNORE,			"ignore" },
181285612Sdelphij	{ RES_DONTSERVE,		"noserve" },
182285612Sdelphij	{ RES_DONTTRUST,		"notrust" },
183285612Sdelphij	{ RES_NOQUERY,			"noquery" },
184285612Sdelphij	{ RES_NOMODIFY,			"nomodify" },
185285612Sdelphij	{ RES_NOPEER,			"nopeer" },
186285612Sdelphij	{ RES_NOTRAP,			"notrap" },
187285612Sdelphij	{ RES_LPTRAP,			"lptrap" },
188285612Sdelphij	{ RES_LIMITED,			"limited" },
189285612Sdelphij	{ RES_VERSION,			"version" },
190285612Sdelphij	{ RES_KOD,			"kod" },
191285612Sdelphij	{ RES_FLAKE,			"flake" },
192285612Sdelphij	/* not used with getcode(), no terminating entry needed */
193285612Sdelphij};
194285612Sdelphij
195285612Sdelphij#ifdef AUTOKEY
196285612Sdelphij/*
197285612Sdelphij * Crypto events (cryp)
198285612Sdelphij */
199285612Sdelphijstatic const struct codestring crypto_codes[] = {
200132451Sroberto	{ XEVNT_OK & ~CRPT_EVENT,	"success" },
201132451Sroberto	{ XEVNT_LEN & ~CRPT_EVENT,	"bad_field_format_or_length" },
202132451Sroberto	{ XEVNT_TSP & ~CRPT_EVENT,	"bad_timestamp" },
203132451Sroberto	{ XEVNT_FSP & ~CRPT_EVENT,	"bad_filestamp" },
204182007Sroberto	{ XEVNT_PUB & ~CRPT_EVENT,	"bad_or_missing_public_key" },
205132451Sroberto	{ XEVNT_MD & ~CRPT_EVENT,	"unsupported_digest_type" },
206132451Sroberto	{ XEVNT_KEY & ~CRPT_EVENT,	"unsupported_identity_type" },
207132451Sroberto	{ XEVNT_SGL & ~CRPT_EVENT,	"bad_signature_length" },
208132451Sroberto	{ XEVNT_SIG & ~CRPT_EVENT,	"signature_not_verified" },
209182007Sroberto	{ XEVNT_VFY & ~CRPT_EVENT,	"certificate_not_verified" },
210285612Sdelphij	{ XEVNT_PER & ~CRPT_EVENT,	"host_certificate_expired" },
211132451Sroberto	{ XEVNT_CKY & ~CRPT_EVENT,	"bad_or_missing_cookie" },
212285612Sdelphij	{ XEVNT_DAT & ~CRPT_EVENT,	"bad_or_missing_leapseconds" },
213132451Sroberto	{ XEVNT_CRT & ~CRPT_EVENT,	"bad_or_missing_certificate" },
214285612Sdelphij	{ XEVNT_ID & ~CRPT_EVENT,	"bad_or_missing_group key" },
215182007Sroberto	{ XEVNT_ERR & ~CRPT_EVENT,	"protocol_error" },
216285612Sdelphij	{ -1,				"" }
217132451Sroberto};
218285612Sdelphij#endif	/* AUTOKEY */
219132451Sroberto
220285612Sdelphij#ifdef KERNEL_PLL
221285612Sdelphij/*
222285612Sdelphij * kernel discipline status bits
223285612Sdelphij */
224285612Sdelphijstatic const struct codestring k_st_bits[] = {
225285612Sdelphij# ifdef STA_PLL
226285612Sdelphij	{ STA_PLL,			"pll" },
227285612Sdelphij# endif
228285612Sdelphij# ifdef STA_PPSFREQ
229285612Sdelphij	{ STA_PPSFREQ,			"ppsfreq" },
230285612Sdelphij# endif
231285612Sdelphij# ifdef STA_PPSTIME
232285612Sdelphij	{ STA_PPSTIME,			"ppstime" },
233285612Sdelphij# endif
234285612Sdelphij# ifdef STA_FLL
235285612Sdelphij	{ STA_FLL,			"fll" },
236285612Sdelphij# endif
237285612Sdelphij# ifdef STA_INS
238285612Sdelphij	{ STA_INS,			"ins" },
239285612Sdelphij# endif
240285612Sdelphij# ifdef STA_DEL
241285612Sdelphij	{ STA_DEL,			"del" },
242285612Sdelphij# endif
243285612Sdelphij# ifdef STA_UNSYNC
244285612Sdelphij	{ STA_UNSYNC,			"unsync" },
245285612Sdelphij# endif
246285612Sdelphij# ifdef STA_FREQHOLD
247285612Sdelphij	{ STA_FREQHOLD,			"freqhold" },
248285612Sdelphij# endif
249285612Sdelphij# ifdef STA_PPSSIGNAL
250285612Sdelphij	{ STA_PPSSIGNAL,		"ppssignal" },
251285612Sdelphij# endif
252285612Sdelphij# ifdef STA_PPSJITTER
253285612Sdelphij	{ STA_PPSJITTER,		"ppsjitter" },
254285612Sdelphij# endif
255285612Sdelphij# ifdef STA_PPSWANDER
256285612Sdelphij	{ STA_PPSWANDER,		"ppswander" },
257285612Sdelphij# endif
258285612Sdelphij# ifdef STA_PPSERROR
259285612Sdelphij	{ STA_PPSERROR,			"ppserror" },
260285612Sdelphij# endif
261285612Sdelphij# ifdef STA_CLOCKERR
262285612Sdelphij	{ STA_CLOCKERR,			"clockerr" },
263285612Sdelphij# endif
264285612Sdelphij# ifdef STA_NANO
265285612Sdelphij	{ STA_NANO,			"nano" },
266285612Sdelphij# endif
267285612Sdelphij# ifdef STA_MODE
268285612Sdelphij	{ STA_MODE,			"mode=fll" },
269285612Sdelphij# endif
270285612Sdelphij# ifdef STA_CLK
271285612Sdelphij	{ STA_CLK,			"src=B" },
272285612Sdelphij# endif
273285612Sdelphij	/* not used with getcode(), no terminating entry needed */
274285612Sdelphij};
275285612Sdelphij#endif	/* KERNEL_PLL */
276285612Sdelphij
27754359Sroberto/* Forwards */
278285612Sdelphijstatic const char *	getcode(int, const struct codestring *);
279285612Sdelphijstatic const char *	getevents(int);
280285612Sdelphijstatic const char *	peer_st_flags(u_char pst);
28154359Sroberto
28254359Sroberto/*
28354359Sroberto * getcode - return string corresponding to code
28454359Sroberto */
28554359Srobertostatic const char *
28654359Srobertogetcode(
287285612Sdelphij	int				code,
288285612Sdelphij	const struct codestring *	codetab
28954359Sroberto	)
29054359Sroberto{
291285612Sdelphij	char *	buf;
29254359Sroberto
29354359Sroberto	while (codetab->code != -1) {
29454359Sroberto		if (codetab->code == code)
295285612Sdelphij			return codetab->string;
29654359Sroberto		codetab++;
29754359Sroberto	}
298285612Sdelphij
299285612Sdelphij	LIB_GETBUF(buf);
300285612Sdelphij	snprintf(buf, LIB_BUFLENGTH, "%s_%d", codetab->string, code);
301285612Sdelphij
30254359Sroberto	return buf;
30354359Sroberto}
30454359Sroberto
30554359Sroberto/*
30654359Sroberto * getevents - return a descriptive string for the event count
30754359Sroberto */
30854359Srobertostatic const char *
30954359Srobertogetevents(
31054359Sroberto	int cnt
31154359Sroberto	)
31254359Sroberto{
313285612Sdelphij	char *	buf;
31454359Sroberto
31554359Sroberto	if (cnt == 0)
316285612Sdelphij		return "no events";
317285612Sdelphij
318285612Sdelphij	LIB_GETBUF(buf);
319285612Sdelphij	snprintf(buf, LIB_BUFLENGTH, "%d event%s", cnt,
320285612Sdelphij		 (1 == cnt)
321285612Sdelphij		     ? ""
322285612Sdelphij		     : "s");
323285612Sdelphij
32454359Sroberto	return buf;
32554359Sroberto}
32654359Sroberto
327285612Sdelphij
32854359Sroberto/*
329285612Sdelphij * decode_bitflags()
330285612Sdelphij *
331285612Sdelphij * returns a human-readable string with a keyword from tab for each bit
332285612Sdelphij * set in bits, separating multiple entries with text of sep2.
333285612Sdelphij */
334285612Sdelphijstatic const char *
335285612Sdelphijdecode_bitflags(
336285612Sdelphij	int				bits,
337285612Sdelphij	const char *			sep2,
338285612Sdelphij	const struct codestring *	tab,
339285612Sdelphij	size_t				tab_ct
340285612Sdelphij	)
341285612Sdelphij{
342285612Sdelphij	const char *	sep;
343285612Sdelphij	char *		buf;
344285612Sdelphij	char *		pch;
345285612Sdelphij	char *		lim;
346285612Sdelphij	size_t		b;
347285612Sdelphij	int		rc;
348285612Sdelphij	int		saved_errno;	/* for use in DPRINTF with %m */
349285612Sdelphij
350285612Sdelphij	saved_errno = errno;
351285612Sdelphij	LIB_GETBUF(buf);
352285612Sdelphij	pch = buf;
353285612Sdelphij	lim = buf + LIB_BUFLENGTH;
354285612Sdelphij	sep = "";
355285612Sdelphij
356285612Sdelphij	for (b = 0; b < tab_ct; b++) {
357285612Sdelphij		if (tab[b].code & bits) {
358285612Sdelphij			rc = snprintf(pch, (lim - pch), "%s%s", sep,
359285612Sdelphij				      tab[b].string);
360285612Sdelphij			if (rc < 0)
361285612Sdelphij				goto toosmall;
362285612Sdelphij			pch += (u_int)rc;
363285612Sdelphij			if (pch >= lim)
364285612Sdelphij				goto toosmall;
365285612Sdelphij			sep = sep2;
366285612Sdelphij		}
367285612Sdelphij	}
368285612Sdelphij
369285612Sdelphij	return buf;
370285612Sdelphij
371285612Sdelphij    toosmall:
372285612Sdelphij	snprintf(buf, LIB_BUFLENGTH,
373285612Sdelphij		 "decode_bitflags(%s) can't decode 0x%x in %d bytes",
374285612Sdelphij		 (tab == peer_st_bits)
375285612Sdelphij		     ? "peer_st"
376285612Sdelphij		     :
377285612Sdelphij#ifdef KERNEL_PLL
378285612Sdelphij		       (tab == k_st_bits)
379285612Sdelphij			   ? "kern_st"
380285612Sdelphij			   :
381285612Sdelphij#endif
382285612Sdelphij			     "",
383285612Sdelphij		 bits, (int)LIB_BUFLENGTH);
384285612Sdelphij	errno = saved_errno;
385285612Sdelphij
386285612Sdelphij	return buf;
387285612Sdelphij}
388285612Sdelphij
389285612Sdelphij
390285612Sdelphijstatic const char *
391285612Sdelphijpeer_st_flags(
392285612Sdelphij	u_char pst
393285612Sdelphij	)
394285612Sdelphij{
395285612Sdelphij	return decode_bitflags(pst, ", ", peer_st_bits,
396285612Sdelphij			       COUNTOF(peer_st_bits));
397285612Sdelphij}
398285612Sdelphij
399285612Sdelphij
400285612Sdelphijconst char *
401285612Sdelphijres_match_flags(
402285612Sdelphij	u_short mf
403285612Sdelphij	)
404285612Sdelphij{
405285612Sdelphij	return decode_bitflags(mf, " ", res_match_bits,
406285612Sdelphij			       COUNTOF(res_match_bits));
407285612Sdelphij}
408285612Sdelphij
409285612Sdelphij
410285612Sdelphijconst char *
411285612Sdelphijres_access_flags(
412285612Sdelphij	u_short af
413285612Sdelphij	)
414285612Sdelphij{
415285612Sdelphij	return decode_bitflags(af, " ", res_access_bits,
416285612Sdelphij			       COUNTOF(res_access_bits));
417285612Sdelphij}
418285612Sdelphij
419285612Sdelphij
420285612Sdelphij#ifdef KERNEL_PLL
421285612Sdelphijconst char *
422285612Sdelphijk_st_flags(
423285612Sdelphij	u_int32 st
424285612Sdelphij	)
425285612Sdelphij{
426285612Sdelphij	return decode_bitflags(st, " ", k_st_bits, COUNTOF(k_st_bits));
427285612Sdelphij}
428285612Sdelphij#endif	/* KERNEL_PLL */
429285612Sdelphij
430285612Sdelphij
431285612Sdelphij/*
43254359Sroberto * statustoa - return a descriptive string for a peer status
43354359Sroberto */
43454359Srobertochar *
43554359Srobertostatustoa(
43654359Sroberto	int type,
43754359Sroberto	int st
43854359Sroberto	)
43954359Sroberto{
440285612Sdelphij	char *	cb;
441285612Sdelphij	char *	cc;
442285612Sdelphij	u_char	pst;
44354359Sroberto
44454359Sroberto	LIB_GETBUF(cb);
44554359Sroberto
44654359Sroberto	switch (type) {
447285612Sdelphij
448285612Sdelphij	case TYPE_SYS:
449285612Sdelphij		snprintf(cb, LIB_BUFLENGTH, "%s, %s, %s, %s",
450285612Sdelphij			 getcode(CTL_SYS_LI(st), leap_codes),
451285612Sdelphij			 getcode(CTL_SYS_SOURCE(st), sync_codes),
452285612Sdelphij			 getevents(CTL_SYS_NEVNT(st)),
453285612Sdelphij			 getcode(CTL_SYS_EVENT(st), sys_codes));
45454359Sroberto		break;
45554359Sroberto
456285612Sdelphij	case TYPE_PEER:
457285612Sdelphij		pst = (u_char)CTL_PEER_STATVAL(st);
458285612Sdelphij		snprintf(cb, LIB_BUFLENGTH, "%s, %s, %s",
459285612Sdelphij			 peer_st_flags(pst),
460285612Sdelphij			 getcode(pst & 0x7, select_codes),
461285612Sdelphij			 getevents(CTL_PEER_NEVNT(st)));
46254359Sroberto		if (CTL_PEER_EVENT(st) != EVNT_UNSPEC) {
463285612Sdelphij			cc = cb + strlen(cb);
464285612Sdelphij			snprintf(cc, LIB_BUFLENGTH - (cc - cb), ", %s",
465285612Sdelphij				 getcode(CTL_PEER_EVENT(st),
466285612Sdelphij					 peer_codes));
46754359Sroberto		}
46854359Sroberto		break;
46954359Sroberto
470285612Sdelphij	case TYPE_CLOCK:
471285612Sdelphij		snprintf(cb, LIB_BUFLENGTH, "%s, %s",
472285612Sdelphij			 getevents(CTL_SYS_NEVNT(st)),
473285612Sdelphij			 getcode((st) & 0xf, clock_codes));
47454359Sroberto		break;
47554359Sroberto	}
476285612Sdelphij
47754359Sroberto	return cb;
47854359Sroberto}
47954359Sroberto
48054359Srobertoconst char *
48154359Srobertoeventstr(
48254359Sroberto	int num
48354359Sroberto	)
48454359Sroberto{
485132451Sroberto	if (num & PEER_EVENT)
486132451Sroberto		return (getcode(num & ~PEER_EVENT, peer_codes));
487285612Sdelphij#ifdef AUTOKEY
488132451Sroberto	else if (num & CRPT_EVENT)
489132451Sroberto		return (getcode(num & ~CRPT_EVENT, crypto_codes));
490285612Sdelphij#endif	/* AUTOKEY */
491132451Sroberto	else
492132451Sroberto		return (getcode(num, sys_codes));
49354359Sroberto}
49454359Sroberto
49554359Srobertoconst char *
49654359Srobertoceventstr(
49754359Sroberto	int num
49854359Sroberto	)
49954359Sroberto{
50054359Sroberto	return getcode(num, clock_codes);
50154359Sroberto}
502