1/* 2 * ntp_stdlib.h - Prototypes for NTP lib. 3 */ 4#ifndef NTP_STDLIB_H 5#define NTP_STDLIB_H 6 7#include <sys/types.h> 8#ifdef HAVE_SYS_SOCKET_H 9#include <sys/socket.h> 10#endif 11 12#include "l_stdlib.h" 13#include "ntp_rfc2553.h" 14#include "ntp_types.h" 15#include "ntp_string.h" 16#include "ntp_net.h" 17#include "ntp_syslog.h" 18 19 20/* 21 * Handle gcc __attribute__ if available. 22 */ 23#ifndef __attribute__ 24/* This feature is available in gcc versions 2.5 and later. */ 25# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || (defined(__STRICT_ANSI__)) 26# define __attribute__(Spec) /* empty */ 27# endif 28/* The __-protected variants of `format' and `printf' attributes 29 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 30# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 31# define __format__ format 32# define __printf__ printf 33# endif 34#endif 35 36extern void msyslog (int, const char *, ...) 37 __attribute__((__format__(__printf__, 2, 3))); 38 39/* 40 * When building without OpenSSL, use a few macros of theirs to 41 * minimize source differences in NTP. 42 */ 43#ifndef OPENSSL 44#define NID_md5 4 /* from openssl/objects.h */ 45/* from openssl/evp.h */ 46#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */ 47#endif 48 49extern void auth_delkeys (void); 50extern int auth_havekey (keyid_t); 51extern int authdecrypt (keyid_t, u_int32 *, int, int); 52extern int authencrypt (keyid_t, u_int32 *, int); 53extern int authhavekey (keyid_t); 54extern int authistrusted (keyid_t); 55extern int authreadkeys (const char *); 56extern void authtrust (keyid_t, u_long); 57extern int authusekey (keyid_t, int, const u_char *); 58 59extern u_long calyearstart (u_long); 60extern const char *clockname (int); 61extern int clocktime (int, int, int, int, int, u_long, u_long *, u_int32 *); 62#if !defined(_MSC_VER) || !defined(_DEBUG) 63extern void * emalloc (size_t); 64extern void * erealloc (void *, size_t); 65extern char * estrdup (const char *); 66#else 67extern void * debug_erealloc (void *, size_t, const char *, int); 68#define emalloc(c) debug_erealloc(NULL, (c), __FILE__, __LINE__) 69#define erealloc(p, c) debug_erealloc((p), (c), __FILE__, __LINE__) 70extern char * debug_estrdup (const char *, const char *, int); 71#define estrdup(s) debug_estrdup((s), __FILE__, __LINE__) 72#endif 73extern int ntp_getopt (int, char **, const char *); 74extern void init_auth (void); 75extern void init_lib (void); 76extern struct savekey *auth_findkey (keyid_t); 77extern int auth_moremem (void); 78extern int ymd2yd (int, int, int); 79 80/* a_md5encrypt.c */ 81extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int); 82extern int MD5authencrypt (int, u_char *, u_int32 *, int); 83extern void MD5auth_setkey (keyid_t, int, const u_char *, const int); 84extern u_int32 addr2refid (sockaddr_u *); 85 86 87extern int atoint (const char *, long *); 88extern int atouint (const char *, u_long *); 89extern int hextoint (const char *, u_long *); 90extern char * humanlogtime (void); 91extern char * inttoa (long); 92extern char * mfptoa (u_long, u_long, short); 93extern char * mfptoms (u_long, u_long, short); 94extern const char * modetoa (int); 95extern const char * eventstr (int); 96extern const char * ceventstr (int); 97extern char * statustoa (int, int); 98extern const char * sysstatstr (int); 99extern const char * peerstatstr (int); 100extern const char * clockstatstr (int); 101extern sockaddr_u * netof (sockaddr_u *); 102extern char * numtoa (u_int32); 103extern char * numtohost (u_int32); 104extern char * socktoa (sockaddr_u *); 105extern char * socktohost (sockaddr_u *); 106extern int octtoint (const char *, u_long *); 107extern u_long ranp2 (int); 108extern char * refnumtoa (sockaddr_u *); 109extern int tsftomsu (u_long, int); 110extern char * uinttoa (u_long); 111 112extern int decodenetnum (const char *, sockaddr_u *); 113 114extern const char * FindConfig (const char *); 115 116extern void signal_no_reset (int, RETSIGTYPE (*func)(int)); 117 118extern void getauthkeys (const char *); 119extern void auth_agekeys (void); 120extern void rereadkeys (void); 121 122/* 123 * Variable declarations for libntp. 124 */ 125 126/* 127 * Defined by any program. 128 */ 129extern volatile int debug; /* debugging flag */ 130 131/* authkeys.c */ 132extern u_long authkeynotfound; /* keys not found */ 133extern u_long authkeylookups; /* calls to lookup keys */ 134extern u_long authnumkeys; /* number of active keys */ 135extern u_long authkeyexpired; /* key lifetime expirations */ 136extern u_long authkeyuncached; /* cache misses */ 137extern u_long authencryptions; /* calls to encrypt */ 138extern u_long authdecryptions; /* calls to decrypt */ 139 140extern int authnumfreekeys; 141 142/* 143 * The key cache. We cache the last key we looked at here. 144 */ 145extern keyid_t cache_keyid; /* key identifier */ 146extern u_char * cache_key; /* key pointer */ 147extern u_int cache_keylen; /* key length */ 148 149/* getopt.c */ 150extern char * ntp_optarg; /* global argument pointer */ 151extern int ntp_optind; /* global argv index */ 152 153/* lib_strbuf.c */ 154extern int ipv4_works; 155extern int ipv6_works; 156 157/* machines.c */ 158typedef void (*pset_tod_using)(const char *); 159extern pset_tod_using set_tod_using; 160 161/* ssl_init.c */ 162#ifdef OPENSSL 163extern void ssl_init (void); 164extern void ssl_check_version (void); 165extern int ssl_init_done; 166#define INIT_SSL() \ 167 do { \ 168 if (!ssl_init_done) \ 169 ssl_init(); \ 170 } while (0) 171#else /* !OPENSSL follows */ 172#define INIT_SSL() do {} while (0) 173#endif 174extern int keytype_from_text (const char *, size_t *); 175extern const char *keytype_name (int); 176 177 178/* lib/isc/win32/strerror.c 179 * 180 * To minimize Windows-specific changes to the rest of the NTP code, 181 * particularly reference clocks, we hijack calls to strerror() to deal 182 * with our mixture of error codes from the C runtime (open, write) 183 * and Windows (sockets, serial ports). This is an ugly hack because 184 * both use the lowest values differently, but particularly for ntpd, 185 * it's not a problem. 186 */ 187#ifdef NTP_REDEFINE_STRERROR 188#define strerror(e) ntp_strerror(e) 189extern char * ntp_strerror (int e); 190#endif 191 192/* systime.c */ 193extern double sys_tick; /* adjtime() resolution */ 194 195/* version.c */ 196extern const char *Version; /* version declaration */ 197 198#endif /* NTP_STDLIB_H */ 199