From cb88cea3c45894f28e3aaa8978c0b80e9d43285e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 7 Aug 2014 14:29:15 +0200 Subject: [PATCH] ntp: move packet size asserts to ntp_core --- ntp_core.c | 28 ++++++++++++++++++++++++++++ ntp_io.c | 29 ----------------------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index 983f7bd..c83f1e8 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -232,9 +232,37 @@ static void transmit_timeout(void *arg); /* ================================================== */ +static void +do_size_checks(void) +{ + /* Assertions to check the sizes of certain data types + and the positions of certain record fields */ + + /* Check that certain invariants are true */ + assert(sizeof(NTP_int32) == 4); + assert(sizeof(NTP_int64) == 8); + + /* Check offsets of all fields in the NTP packet format */ + assert(offsetof(NTP_Packet, lvm) == 0); + assert(offsetof(NTP_Packet, stratum) == 1); + assert(offsetof(NTP_Packet, poll) == 2); + assert(offsetof(NTP_Packet, precision) == 3); + assert(offsetof(NTP_Packet, root_delay) == 4); + assert(offsetof(NTP_Packet, root_dispersion) == 8); + assert(offsetof(NTP_Packet, reference_id) == 12); + assert(offsetof(NTP_Packet, reference_ts) == 16); + assert(offsetof(NTP_Packet, originate_ts) == 24); + assert(offsetof(NTP_Packet, receive_ts) == 32); + assert(offsetof(NTP_Packet, transmit_ts) == 40); +} + +/* ================================================== */ + void NCR_Initialise(void) { + do_size_checks(); + logfileid = CNF_GetLogMeasurements() ? LOG_FileOpen("measurements", " Date (UTC) Time IP Address L St 1234 abc 5678 LP RP Score Offset Peer del. Peer disp. Root del. Root disp.") : -1; diff --git a/ntp_io.c b/ntp_io.c index 0100a90..72f6a66 100644 --- a/ntp_io.c +++ b/ntp_io.c @@ -71,33 +71,6 @@ static void read_from_socket(void *anything); /* ================================================== */ -static void -do_size_checks(void) -{ - /* Assertions to check the sizes of certain data types - and the positions of certain record fields */ - - /* Check that certain invariants are true */ - assert(sizeof(NTP_int32) == 4); - assert(sizeof(NTP_int64) == 8); - - /* Check offsets of all fields in the NTP packet format */ - assert(offsetof(NTP_Packet, lvm) == 0); - assert(offsetof(NTP_Packet, stratum) == 1); - assert(offsetof(NTP_Packet, poll) == 2); - assert(offsetof(NTP_Packet, precision) == 3); - assert(offsetof(NTP_Packet, root_delay) == 4); - assert(offsetof(NTP_Packet, root_dispersion) == 8); - assert(offsetof(NTP_Packet, reference_id) == 12); - assert(offsetof(NTP_Packet, reference_ts) == 16); - assert(offsetof(NTP_Packet, originate_ts) == 24); - assert(offsetof(NTP_Packet, receive_ts) == 32); - assert(offsetof(NTP_Packet, transmit_ts) == 40); - -} - -/* ================================================== */ - static int prepare_socket(int family, int port_number, int client_only) { @@ -323,8 +296,6 @@ NIO_Initialise(int family) assert(!initialised); initialised = 1; - do_size_checks(); - server_port = CNF_GetNTPPort(); client_port = CNF_GetAcquisitionPort();