[ntp:questions] Extracting ntpq like information programmatically

unruh unruh at invalid.ca
Fri Mar 29 15:59:42 UTC 2013


On 2013-03-28, Claudio Carbone <erupter at libero.it> wrote:
> Hello.
>
> I'm new to NTP and my needs aren't really rooted in the mechanism of 
> synchronization and time seeding.
>
> What I intend to do is a kind of ping/traceroute of a networked 
> architecture where OS level ping and traceroutes do not suffice.
>
> So I'm designing my own little apps to push messages around.
> But in order to compare timestamps from different computers I thought it 
> best to carry NTP offset/jitter/delay values to be able to adjust values 
> after the measure and obtain a better accuracy.
>
> Now what I want to ask is:
> -how can I get this kind of info in my program (is there a library? I 
> read mentions of libntp but ubuntu has nothing of the sort)
> -your comments about my ideas
> -a brief explanation of exactly what offset and delay mean and to which 
> one jitter is related
>  From what I read here 
><http://www.eecis.udel.edu/%7Emills/ntp/html/warp.html> /delay/ seems 
> like a kind of ping, but then I wouldn't understand its meaning or use 
> in the NTP system.

ntp works by sending a special packet to another machine. That packet
has four timestamp fields. When it is sent out, the first entry is the
time, according to the machine which sent the packet. When the second
machine receives the packet it immediately enters the receipt time (
according to its clock). It then does its processing of the request in
the packet, and sends back the packet, with the time at which it was
sent back in the third field. When the first computer receives the
packet back, it places the receipt time into the fourth field. (the
above it not quite right as to the fields containing these values, but
the complication is irrelevant here). This is not like ping, where the
only timestamps are from the sending machine, and those timestamps are
not carried by the packet, AFAIK, but are remembered in the machine
itself along with the packet number. 

Delay is t4-t1, the difference in time as measured by the sending
machine. Offset is (t4+t1)/2 -(t3+t2)/2 -- ie the difference in the
average time of sending and receiving by the first machine  and the average time 
between sending and receiving by the second. It is the best estimate of
the difference in time between the two machines' clocks (relativistic effects
are treated as irrelevant). 

I have no idea what you want to do-- your description just left me
confused, but perhaps the above may allow you to decide if the ntp
protocol might be useful to you. 
Note that the packet exchange procedure assumes that both machines have
the approriate program running to provice those time stamps. It is not
there by default on any system, and must thus be specially started up.
Since almost all of ntp is concerned with what to do with that
information of the offset and delay once it has been received, almost
everything in libntp or in ntpd is completely irrelevant to you and is
just a waste of memory. 



More information about the questions mailing list