Вопрос

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?

Это было полезно?

Решение

Just from this bit you posted I believe you should be able to get T4 in the same manner through which you got T1 (aka, they are both the time according to the local machine when it processes the particular stage of the request).

Originate Timestamp (T1): time request sent by client
Destination Timestamp (T4): time reply received by client

Oops, my bad assumption.

Would it be sufficient to use something like the C gettimeofday function to create your own timestamp right after you receive the response packet?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top