.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Net::NTP 3pm" .TH Net::NTP 3pm "2015-09-06" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .ie n .SS "offset($packet, $xmttime, $rectime)" .el .SS "offset($packet, \f(CW$xmttime\fP, \f(CW$rectime\fP)" .IX Subsection "offset($packet, $xmttime, $rectime)" Given a \s-1NTP\s0 Packet (from B), return the offset to local (A) according to its xmttime(T1) and rectime(T4) .PP .Vb 1 \& theta = T(B) \- T(A) = 1/2 * [(T2\-T1) + (T3\-T4)] .Ve .ie n .SS "delay($packet, $xmttime, $rectime)" .el .SS "delay($packet, \f(CW$xmttime\fP, \f(CW$rectime\fP)" .IX Subsection "delay($packet, $xmttime, $rectime)" Return the delay from the sender (B) of \f(CW$packet\fR given known local xmttime(T1) and rectime(T4) .PP .Vb 1 \& delta = T(ABA) = (T4\-T1) \- (T3\-T2). .Ve .SH "NAME" Net::NTP \- Perl extension for decoding NTP server responses .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Net::NTP qw(get_ntp_response); \& use Time::HiRes qw(time); \& my %response = get_ntp_response(); \& \& my $xmttime = time(); \& my $spkt = Net::NTP::Packet\->new_client_packet($xmttime); \& $socket\->send($pkt\->encode()); \& $socket\->recv(my $data, 1024); \& my $rectime = time(); \& my $cpkt = Net::NTP::Packet\->decode($data, $xmttime, $rectime); \& print "Stratum: ", $cpkt\->{stratum}, "\en"; \& print "Offset: ", Net::NTP\->offset($pkt, $xmttime, $rectime), "\en" .Ve .SH "ABSTRACT" .IX Header "ABSTRACT" All this module does is send a packet to an \s-1NTP\s0 server and then decode the packet received into it's respective parts \- as outlined in \&\s-1RFC5905 \s0(superseding \s-1RFC1305\s0 and \s-1RFC2030\s0). .SH "LIMITATIONS" .IX Header "LIMITATIONS" This only supports Association Mode 3 (Client). .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module exports a single method (get_ntp_response) and returns an associative array based upon \s-1RFC1305\s0 and \s-1RFC2030. \s0 The response from the server is \*(L"humanized\*(R" to a point that further processing of the information received from the server can be manipulated. For example: timestamps are in epoch, so one could use the localtime function to produce an even more \*(L"human\*(R" representation of the timestamp. .SS "\s-1EXPORT\s0" .IX Subsection "EXPORT" get_ntp_response(, ); .PP This module exports a single method \- get_ntp_response. It takes the server as the first argument (localhost is the default) and port to send/recieve the packets (ntp or 123 by default). It returns an associative array of the various parts of the packet as outlined in \&\s-1RFC1305. \s0 It \*(L"normalizes\*(R" or \*(L"humanizes\*(R" various parts of the packet. For example: all the timestamps are in epoch, \s-1NOT\s0 hexidecimal. .PP Two special fields (\f(CW\*(C`Delay\*(C'\fR and \f(CW\*(C`Offset\*(C'\fR) are calculated and added to the response. .PP If there's a timeout or other communications error get_ntp_response will die (so call get_ntp_response in an eval block). .SH "SEE ALSO" .IX Header "SEE ALSO" perl, IO::Socket, \s-1RFC5905, RFC1305, RFC2030\s0 .SH "AUTHOR" .IX Header "AUTHOR" Now maintained by Ask Bjo\*/rn Hansen, .PP Originally by James G. Willmore, or .PP Special thanks to Ralf D. Kloth for the code to decode \s-1NTP\s0 packets. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2009 by Ask Bjo\*/rn Hansen; 2004 by James G. Willmore .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "NAME" Net::NTP::Packet .SH "DESCRIPTION" .IX Header "DESCRIPTION" Representation of a \s-1NTP\s0 Packet with serialization primitives. .SS "\s-1PROTOCOL \- RFC 5905 \-\s0 Section 7." .IX Subsection "PROTOCOL - RFC 5905 - Section 7." .Vb 10 \& 0 1 2 3 \& 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& |LI | VN |Mode | Stratum | Poll | Precision | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | Root Delay | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | Root Dispersion | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | Reference ID | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& + Reference Timestamp (64) + \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& + Origin Timestamp (64) + \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& + Receive Timestamp (64) + \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& + Transmit Timestamp (64) + \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& . . \& . Extension Field 1 (variable) . \& . . \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& . . \& . Extension Field 2 (variable) . \& . . \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | Key Identifier | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ \& | | \& | dgst (128) | \& | | \& +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+ .Ve .SS "new" .IX Subsection "new" create a new Net::NTP::Packet instance. .PP Parameters are the field names, gotten from \*(L"7.3. Packet Header Variables\*(R" .SS "new_client_packet($xmttime)" .IX Subsection "new_client_packet($xmttime)" Make a packet in association mode 'Client' to be sent to a server. .SS "\fIencode()\fP" .IX Subsection "encode()" Encode a packet to its wire format. \&\s-1NOTE:\s0 It only encodes server packets at the moment. .ie n .SS "$packet = Net::NTP::Packet\->decode($data, $xmttime, $rectime)" .el .SS "\f(CW$packet\fP = Net::NTP::Packet\->decode($data, \f(CW$xmttime\fP, \f(CW$rectime\fP)" .IX Subsection "$packet = Net::NTP::Packet->decode($data, $xmttime, $rectime)" decode the \s-1NTP\s0 packet from its wire format.