xref: /freebsd/contrib/ntp/ntpq/libntpq.h (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
1 /*****************************************************************************
2  *
3  *  libntpq.h
4  *
5  *  This is the wrapper library for ntpq, the NTP query utility.
6  *  This library reuses the sourcecode from ntpq and exports a number
7  *  of useful functions in a library that can be linked against applications
8  *  that need to query the status of a running ntpd. The whole
9  *  communcation is based on mode 6 packets.
10  *
11  * This header file can be used in applications that want to link against
12  * libntpq.
13  *
14  ****************************************************************************/
15 
16 #include "ntp_net.h"
17 
18 /* general purpose buffer size */
19 #define NTPQ_BUFLEN 2048
20 
21 /* max. number of associations */
22 #ifndef MAXASSOC
23 #define MAXASSOC    1024
24 #endif
25 
26 /* general purpose max array size definition */
27 #ifndef MAXLIST
28 #define MAXLIST 64
29 #endif
30 
31 #ifndef LENHOSTNAME
32 #define LENHOSTNAME 256     /* host name is max. 256 characters long */
33 #endif
34 
35 /* NTP Status codes */
36 #define NTP_STATUS_INVALID      0
37 #define NTP_STATUS_FALSETICKER  1
38 #define NTP_STATUS_EXCESS       2
39 #define NTP_STATUS_OUTLIER      3
40 #define NTP_STATUS_CANDIDATE    4
41 #define NTP_STATUS_SELECTED     5
42 #define NTP_STATUS_SYSPEER      6
43 #define NTP_STATUS_PPSPEER      7
44 
45 /* NTP association type identifier */
46 #define NTP_CLOCKTYPE_UNKNOWN   '-'
47 #define NTP_CLOCKTYPE_BROADCAST 'b'
48 #define NTP_CLOCKTYPE_LOCAL     'l'
49 #define NTP_CLOCKTYPE_UNICAST   'u'
50 #define NTP_CLOCKTYPE_MULTICAST 'm'
51 
52 /* Variable Sets */
53 #define PEERVARS CTL_OP_READVAR
54 #define CLOCKVARS CTL_OP_CLOCKVAR
55 
56 /* Variable list struct */
57 struct ntpq_varlist {
58 	char *name;
59 	char *value;
60 };
61 
62 /* global variables used for holding snapshots of data */
63 #ifndef LIBNTPQ_C
64 extern char peervars[];
65 extern int peervarlen;
66 extern int peervar_assoc;
67 extern char clockvars[];
68 extern int clockvarlen;
69 extern int clockvar_assoc;
70 extern char sysvars[];
71 extern int sysvarlen;
72 extern char *ntpq_resultbuffer[];
73 extern struct ntpq_varlist ntpq_varlist[MAXLIST];
74 #endif
75 
76 
77 
78 /*
79  * Prototypes of exported libary functions
80  */
81 
82 /* from libntpq.c */
83 extern int ntpq_openhost(char *, int);
84 extern int ntpq_closehost(void);
85 extern int ntpq_queryhost(unsigned short VARSET, associd_t association,
86 			  char *resultbuf, int maxlen);
87 extern size_t ntpq_getvar(const char *resultbuf, size_t datalen,
88 			  const char *varname, char *varvalue,
89 			  size_t maxlen);
90 extern int ntpq_stripquotes ( char *resultbuf, char *srcbuf, int datalen, int maxlen );
91 extern int ntpq_queryhost_peervars(associd_t association, char *resultbuf, int maxlen);
92 extern int ntpq_get_peervar( const char *varname, char *varvalue, int maxlen);
93 extern size_t ntpq_read_sysvars(char *resultbuf, size_t maxsize);
94 extern int ntpq_get_sysvars( void );
95 extern int ntpq_read_associations ( unsigned short resultbuf[], int max_entries );
96 extern int ntpq_get_assocs ( void );
97 extern int ntpq_get_assoc_number ( associd_t associd );
98 extern int ntpq_get_assoc_peervars( associd_t associd );
99 extern int ntpq_get_assoc_clockvars( associd_t associd );
100 extern int ntpq_get_assoc_allvars( associd_t associd  );
101 extern int ntpq_get_assoc_clocktype(int assoc_index);
102 extern int ntpq_read_assoc_peervars( associd_t associd, char *resultbuf, int maxsize );
103 extern int ntpq_read_assoc_clockvars( associd_t associd, char *resultbuf, int maxsize );
104 
105 /* in libntpq_subs.c */
106 extern int ntpq_dogetassoc(void);
107 extern char ntpq_decodeaddrtype(sockaddr_u *sock);
108 extern int ntpq_doquerylist(struct ntpq_varlist *, int, associd_t, int,
109 			    u_short *, size_t *, const char **datap);
110