I'm trying to create a simple SNTP client in C using the Berkeley sockets API, but I'm having trouble calculating the adjusted time from the response message. I got this from RFC2030.
When the server reply is received, the client determines a Destination Timestamp variable as the time of arrival according to its clock in NTP timestamp format. The following table summarizes the four timestamps.
- Originate Timestamp (T1): time request sent by client
- Receive Timestamp (T2): time request received by server
- Transmit Timestamp (T3): time reply sent by server
- Destination Timestamp (T4): time reply received by client
As far as I can tell, I can calculate the adjusted current time by taking the client's time and adding the time offset t to it, with the time offset defined as
t = ((T2 - T1) + (T3 - T4)) / 2
I'd need to know T4 to make this calculation, but it's not a part of the packet's message. How can I obtain this timestamp?