12b15cb3dSCy Schubert /***************************************************************************** 22b15cb3dSCy Schubert * 32b15cb3dSCy Schubert * libntpq.h 42b15cb3dSCy Schubert * 52b15cb3dSCy Schubert * This is the wrapper library for ntpq, the NTP query utility. 62b15cb3dSCy Schubert * This library reuses the sourcecode from ntpq and exports a number 72b15cb3dSCy Schubert * of useful functions in a library that can be linked against applications 82b15cb3dSCy Schubert * that need to query the status of a running ntpd. The whole 92b15cb3dSCy Schubert * communcation is based on mode 6 packets. 102b15cb3dSCy Schubert * 112b15cb3dSCy Schubert * This header file can be used in applications that want to link against 122b15cb3dSCy Schubert * libntpq. 132b15cb3dSCy Schubert * 142b15cb3dSCy Schubert ****************************************************************************/ 152b15cb3dSCy Schubert 162b15cb3dSCy Schubert #include "ntp_net.h" 172b15cb3dSCy Schubert 182b15cb3dSCy Schubert /* general purpose buffer size */ 192b15cb3dSCy Schubert #define NTPQ_BUFLEN 2048 202b15cb3dSCy Schubert 212b15cb3dSCy Schubert /* max. number of associations */ 222b15cb3dSCy Schubert #ifndef MAXASSOC 232b15cb3dSCy Schubert #define MAXASSOC 1024 242b15cb3dSCy Schubert #endif 252b15cb3dSCy Schubert 262b15cb3dSCy Schubert /* general purpose max array size definition */ 272b15cb3dSCy Schubert #ifndef MAXLIST 282b15cb3dSCy Schubert #define MAXLIST 64 292b15cb3dSCy Schubert #endif 302b15cb3dSCy Schubert 312b15cb3dSCy Schubert #ifndef LENHOSTNAME 322b15cb3dSCy Schubert #define LENHOSTNAME 256 /* host name is max. 256 characters long */ 332b15cb3dSCy Schubert #endif 342b15cb3dSCy Schubert 352b15cb3dSCy Schubert /* NTP Status codes */ 362b15cb3dSCy Schubert #define NTP_STATUS_INVALID 0 372b15cb3dSCy Schubert #define NTP_STATUS_FALSETICKER 1 382b15cb3dSCy Schubert #define NTP_STATUS_EXCESS 2 399034852cSGleb Smirnoff #define NTP_STATUS_OUTLIER 3 402b15cb3dSCy Schubert #define NTP_STATUS_CANDIDATE 4 412b15cb3dSCy Schubert #define NTP_STATUS_SELECTED 5 422b15cb3dSCy Schubert #define NTP_STATUS_SYSPEER 6 432b15cb3dSCy Schubert #define NTP_STATUS_PPSPEER 7 442b15cb3dSCy Schubert 452b15cb3dSCy Schubert /* NTP association type identifier */ 462b15cb3dSCy Schubert #define NTP_CLOCKTYPE_UNKNOWN '-' 472b15cb3dSCy Schubert #define NTP_CLOCKTYPE_BROADCAST 'b' 482b15cb3dSCy Schubert #define NTP_CLOCKTYPE_LOCAL 'l' 492b15cb3dSCy Schubert #define NTP_CLOCKTYPE_UNICAST 'u' 502b15cb3dSCy Schubert #define NTP_CLOCKTYPE_MULTICAST 'm' 512b15cb3dSCy Schubert 522b15cb3dSCy Schubert /* Variable Sets */ 532b15cb3dSCy Schubert #define PEERVARS CTL_OP_READVAR 542b15cb3dSCy Schubert #define CLOCKVARS CTL_OP_CLOCKVAR 552b15cb3dSCy Schubert 562b15cb3dSCy Schubert /* Variable list struct */ 572b15cb3dSCy Schubert struct ntpq_varlist { 582b15cb3dSCy Schubert char *name; 592b15cb3dSCy Schubert char *value; 602b15cb3dSCy Schubert }; 612b15cb3dSCy Schubert 622b15cb3dSCy Schubert /* global variables used for holding snapshots of data */ 632b15cb3dSCy Schubert #ifndef LIBNTPQ_C 642b15cb3dSCy Schubert extern char peervars[]; 652b15cb3dSCy Schubert extern int peervarlen; 662b15cb3dSCy Schubert extern int peervar_assoc; 672b15cb3dSCy Schubert extern char clockvars[]; 682b15cb3dSCy Schubert extern int clockvarlen; 692b15cb3dSCy Schubert extern int clockvar_assoc; 702b15cb3dSCy Schubert extern char sysvars[]; 712b15cb3dSCy Schubert extern int sysvarlen; 722b15cb3dSCy Schubert extern char *ntpq_resultbuffer[]; 732b15cb3dSCy Schubert extern struct ntpq_varlist ntpq_varlist[MAXLIST]; 742b15cb3dSCy Schubert #endif 752b15cb3dSCy Schubert 762b15cb3dSCy Schubert 772b15cb3dSCy Schubert 782b15cb3dSCy Schubert /* 792b15cb3dSCy Schubert * Prototypes of exported libary functions 802b15cb3dSCy Schubert */ 812b15cb3dSCy Schubert 822b15cb3dSCy Schubert /* from libntpq.c */ 832b15cb3dSCy Schubert extern int ntpq_openhost(char *, int); 842b15cb3dSCy Schubert extern int ntpq_closehost(void); 852b15cb3dSCy Schubert extern int ntpq_queryhost(unsigned short VARSET, associd_t association, 862b15cb3dSCy Schubert char *resultbuf, int maxlen); 872b15cb3dSCy Schubert extern size_t ntpq_getvar(const char *resultbuf, size_t datalen, 882b15cb3dSCy Schubert const char *varname, char *varvalue, 892b15cb3dSCy Schubert size_t maxlen); 902b15cb3dSCy Schubert extern int ntpq_stripquotes ( char *resultbuf, char *srcbuf, int datalen, int maxlen ); 912b15cb3dSCy Schubert extern int ntpq_queryhost_peervars(associd_t association, char *resultbuf, int maxlen); 922b15cb3dSCy Schubert extern int ntpq_get_peervar( const char *varname, char *varvalue, int maxlen); 932b15cb3dSCy Schubert extern size_t ntpq_read_sysvars(char *resultbuf, size_t maxsize); 942b15cb3dSCy Schubert extern int ntpq_get_sysvars( void ); 952b15cb3dSCy Schubert extern int ntpq_read_associations ( unsigned short resultbuf[], int max_entries ); 962b15cb3dSCy Schubert extern int ntpq_get_assocs ( void ); 972b15cb3dSCy Schubert extern int ntpq_get_assoc_number ( associd_t associd ); 982b15cb3dSCy Schubert extern int ntpq_get_assoc_peervars( associd_t associd ); 992b15cb3dSCy Schubert extern int ntpq_get_assoc_clockvars( associd_t associd ); 1002b15cb3dSCy Schubert extern int ntpq_get_assoc_allvars( associd_t associd ); 1012b15cb3dSCy Schubert extern int ntpq_get_assoc_clocktype(int assoc_index); 1022b15cb3dSCy Schubert extern int ntpq_read_assoc_peervars( associd_t associd, char *resultbuf, int maxsize ); 1032b15cb3dSCy Schubert extern int ntpq_read_assoc_clockvars( associd_t associd, char *resultbuf, int maxsize ); 1042b15cb3dSCy Schubert 1052b15cb3dSCy Schubert /* in libntpq_subs.c */ 1062b15cb3dSCy Schubert extern int ntpq_dogetassoc(void); 1072b15cb3dSCy Schubert extern char ntpq_decodeaddrtype(sockaddr_u *sock); 1082b15cb3dSCy Schubert extern int ntpq_doquerylist(struct ntpq_varlist *, int, associd_t, int, 109*3311ff84SXin LI u_short *, size_t *, const char **datap); 110