f679b104e625c889308a1274f07b3cb7466fdf4a
4 * arguments: <max-skew> <max-age>
6 * encoding: prepend 4 bytes of UNIX time in network byte order
8 * <max-age> is maximum age in seconds we will accept a packet (or 0
9 * for any age); <max-skew> is maximum future age in seconds we will
10 * accept a packet (or 0 for any future age).
15 #include <netinet/in.h>
20 uint32_t max_skew
, max_age
;
23 static void mds_timestamp(struct mechdata
**md_r
) {
26 md
= xmalloc(sizeof(md
));
28 md
->max_skew
= getarg_ulong();
29 md
->max_age
= getarg_ulong();
33 static void mes_timestamp(struct mechdata
**md_r
, int *maxprefix_io
, int *maxsuffix_io
) {
38 static void menc_timestamp(struct mechdata
*md
, struct buffer
*buf
) {
39 *(uint32_t*)buf_prepend(buf
,4)= htonl(now());
42 static const char *mdec_timestamp(struct mechdata
*md
, struct buffer
*buf
) {
45 uint32_t *tp
, timestamp
, tnow
;
48 BUF_UNPREPEND(tp
,buf
,4);
49 timestamp
= ntohl(*tp
);
52 age
= timestamp
- tnow
;
54 if (md
->max_age
&& age
> md
->max_age
) {
55 sprintf(cbuf
,"packet too old (%lds)",age
);
59 if (md
->max_skew
&& age
> md
->max_skew
) {
60 sprintf(cbuf
,"too much skew (%lds)",-age
);
68 STANDARD_MECHANISMLIST("timestamp",timestamp
);