.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" 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 >0, 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 .\" ======================================================================== .\" .IX Title "Net::NTP 3pm" .TH Net::NTP 3pm "2022-10-13" "perl v5.34.0" "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 Bjø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 Bjø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\s0 \- \s-1RFC 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 "\fBencode()\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.