]> git.ipfire.org Git - thirdparty/chrony.git/blob - util.h
Remove unnecessary adjtimex calls
[thirdparty/chrony.git] / util.h
1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Richard P. Curnow 1997-2003
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 Various utility functions
25 */
26
27 #ifndef GOT_UTIL_H
28 #define GOT_UTIL_H
29
30 #include "sysincl.h"
31
32 #include "addressing.h"
33 #include "ntp.h"
34 #include "candm.h"
35 #include "hash.h"
36
37 /* Convert a timeval into a floating point number of seconds */
38 extern void UTI_TimevalToDouble(struct timeval *a, double *b);
39
40 /* Convert a number of seconds expressed in floating point into a
41 timeval */
42 extern void UTI_DoubleToTimeval(double a, struct timeval *b);
43
44 /* Returns -1 if a comes earlier than b, 0 if a is the same time as b,
45 and +1 if a comes after b */
46 extern int UTI_CompareTimevals(struct timeval *a, struct timeval *b);
47
48 /* Normalise a struct timeval, by adding or subtracting seconds to bring
49 its microseconds field into range */
50 extern void UTI_NormaliseTimeval(struct timeval *x);
51
52 /* Calculate result = a - b */
53 extern void UTI_DiffTimevals(struct timeval *result, struct timeval *a, struct timeval *b);
54
55 /* Calculate result = a - b and return as a double */
56 extern void UTI_DiffTimevalsToDouble(double *result, struct timeval *a, struct timeval *b);
57
58 /* Add a double increment to a timeval to get a new one. 'start' is
59 the starting time, 'end' is the result that we return. This is
60 safe to use if start and end are the same */
61 extern void UTI_AddDoubleToTimeval(struct timeval *start, double increment, struct timeval *end);
62
63 /* Calculate the average and difference (as a double) of two timevals */
64 extern void UTI_AverageDiffTimevals(struct timeval *earlier, struct timeval *later, struct timeval *average, double *diff);
65
66 /* Calculate result = a - b + c */
67 extern void UTI_AddDiffToTimeval(struct timeval *a, struct timeval *b, struct timeval *c, struct timeval *result);
68
69 /* Convert a timeval into a temporary string, largely for diagnostic
70 display */
71 extern char *UTI_TimevalToString(struct timeval *tv);
72
73 /* Convert an NTP timestamp into a temporary string, largely for
74 diagnostic display */
75 extern char *UTI_TimestampToString(NTP_int64 *ts);
76
77 /* Convert ref_id into a temporary string, for diagnostics */
78 extern char *UTI_RefidToString(uint32_t ref_id);
79
80 /* Convert an IP address to string, for diagnostics */
81 extern char *UTI_IPToString(IPAddr *ip);
82
83 extern int UTI_StringToIP(const char *addr, IPAddr *ip);
84 extern uint32_t UTI_IPToRefid(IPAddr *ip);
85 extern void UTI_IPHostToNetwork(IPAddr *src, IPAddr *dest);
86 extern void UTI_IPNetworkToHost(IPAddr *src, IPAddr *dest);
87 extern int UTI_CompareIPs(IPAddr *a, IPAddr *b, IPAddr *mask);
88
89 extern char *UTI_TimeToLogForm(time_t t);
90
91 /* Adjust time following a frequency/offset change */
92 extern void UTI_AdjustTimeval(struct timeval *old_tv, struct timeval *when, struct timeval *new_tv, double *delta, double dfreq, double doffset);
93
94 /* Get a random value to fuzz an NTP timestamp in the given precision */
95 extern uint32_t UTI_GetNTPTsFuzz(int precision);
96
97 extern double UTI_Int32ToDouble(NTP_int32 x);
98 extern NTP_int32 UTI_DoubleToInt32(double x);
99
100 extern void UTI_TimevalToInt64(struct timeval *src, NTP_int64 *dest, uint32_t fuzz);
101
102 extern void UTI_Int64ToTimeval(NTP_int64 *src, struct timeval *dest);
103
104 extern void UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest);
105 extern void UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest);
106
107 extern double UTI_FloatNetworkToHost(Float x);
108 extern Float UTI_FloatHostToNetwork(double x);
109
110 /* Set FD_CLOEXEC on descriptor */
111 extern void UTI_FdSetCloexec(int fd);
112
113 extern int UTI_GenerateNTPAuth(int hash_id, const unsigned char *key, int key_len,
114 const unsigned char *data, int data_len, unsigned char *auth, int auth_len);
115 extern int UTI_CheckNTPAuth(int hash_id, const unsigned char *key, int key_len,
116 const unsigned char *data, int data_len, const unsigned char *auth, int auth_len);
117
118 /* Decode password encoded in ASCII or HEX */
119 extern int UTI_DecodePasswordFromText(char *key);
120
121 #if defined (INLINE_UTILITIES)
122 #define INLINE_STATIC inline static
123 #include "util.c"
124 #else
125 #define INLINE_STATIC
126 #endif /* defined (INLINE_UTILITIES) */
127
128 #endif /* GOT_UTIL_H */