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