pkt.stratum = 0;
pkt.poll = 4;
pkt.precision = -6; /* as ntpdate */
- pkt.root_delay = double_to_int32(1.0); /* 1 second */
- pkt.root_dispersion = double_to_int32(1.0); /* likewise */
+ pkt.root_delay = UTI_DoubleToInt32(1.0); /* 1 second */
+ pkt.root_dispersion = UTI_DoubleToInt32(1.0); /* likewise */
pkt.reference_id = 0;
pkt.reference_ts.hi = 0; /* Set to 0 */
pkt.reference_ts.lo = 0; /* Set to 0 */
return;
}
- root_delay = int32_to_double(msg->root_delay);
- root_dispersion = int32_to_double(msg->root_dispersion);
+ root_delay = UTI_Int32ToDouble(msg->root_delay);
+ root_dispersion = UTI_Int32ToDouble(msg->root_dispersion);
UTI_Int64ToTimeval(&src->last_tx, &local_orig);
UTI_Int64ToTimeval(&msg->receive_ts, &remote_rx);
/* If we're sending a client mode packet and we aren't synchronized yet,
we might have to set up artificial values for some of these parameters */
- message.root_delay = double_to_int32(our_root_delay);
- message.root_dispersion = double_to_int32(our_root_dispersion);
+ message.root_delay = UTI_DoubleToInt32(our_root_delay);
+ message.root_dispersion = UTI_DoubleToInt32(our_root_dispersion);
message.reference_id = htonl((NTP_int32) our_ref_id);
#define NTP_NORMAL_PACKET_SIZE offsetof(NTP_Packet, auth_keyid)
-/* ================================================== */
-
-inline static double
-int32_to_double(NTP_int32 x)
-{
- return (double) ntohl(x) / 65536.0;
-}
-
-/* ================================================== */
-
-inline static NTP_int32
-double_to_int32(double x)
-{
- return htonl((NTP_int32)(0.5 + 65536.0 * x));
-}
-
-/* ================================================== */
-
#endif /* GOT_NTP_H */
/* If we're sending a client mode packet and we aren't synchronized yet,
we might have to set up artificial values for some of these parameters */
- message.root_delay = double_to_int32(our_root_delay);
- message.root_dispersion = double_to_int32(our_root_dispersion);
+ message.root_delay = UTI_DoubleToInt32(our_root_delay);
+ message.root_dispersion = UTI_DoubleToInt32(our_root_dispersion);
message.reference_id = htonl((NTP_int32) our_ref_id);
source_is_synchronized = 1;
}
- pkt_root_delay = int32_to_double(message->root_delay);
- pkt_root_dispersion = int32_to_double(message->root_dispersion);
+ pkt_root_delay = UTI_Int32ToDouble(message->root_delay);
+ pkt_root_dispersion = UTI_Int32ToDouble(message->root_dispersion);
/* Perform packet validity tests */
/* ================================================== */
+double
+UTI_Int32ToDouble(NTP_int32 x)
+{
+ return (double) ntohl(x) / 65536.0;
+}
+
+/* ================================================== */
+
+NTP_int32
+UTI_DoubleToInt32(double x)
+{
+ return htonl((NTP_int32)(0.5 + 65536.0 * x));
+}
+
+/* ================================================== */
+
/* Seconds part of RFC1305 timestamp correponding to the origin of the
struct timeval format. */
#define JAN_1970 0x83aa7e80UL
/* Get a random value to fuzz an NTP timestamp in the given precision */
extern uint32_t UTI_GetNTPTsFuzz(int precision);
+extern double UTI_Int32ToDouble(NTP_int32 x);
+extern NTP_int32 UTI_DoubleToInt32(double x);
+
extern void UTI_TimevalToInt64(struct timeval *src, NTP_int64 *dest, uint32_t fuzz);
extern void UTI_Int64ToTimeval(NTP_int64 *src, struct timeval *dest);