The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::Frame::Layer::NTP - NTP layer object

SYNOPSIS

   use Net::Frame::Simple;
   use Net::Frame::Layer::NTP qw(:consts);

   my $layer = Net::Frame::Layer::NTP->new(
      leap         => NF_NTP_LI_NOWARN,
      version      => 3,
      mode         => NF_NTP_MODE_CLIENT,
      stratum      => NF_NTP_STRATUM_UNSPEC,
      poll         => 0,
      precision    => 0,
      rootDelay    => 0,
      rootDisp     => 0,
      refId        => 0,
      refTime      => 0,
      refTime_frac => 0,
      org          => 0,
      org_frac     => 0,
      rec          => 0,
      rec_frac     => 0,
      xmt          => ntpTimestamp(time),
      xmt_frac     => 0,
   );

   #
   # Read a raw layer
   #

   my $layer = Net::Frame::Layer::NTP->new(raw => $raw);

   print $layer->print."\n";
   print 'PAYLOAD: '.unpack('H*', $layer->payload)."\n"
      if $layer->payload;

DESCRIPTION

This modules implements the encoding and decoding of the NTP layer.

RFC: ftp://ftp.rfc-editor.org/in-notes/rfc1305.txt

See also Net::Frame::Layer for other attributes and methods.

ATTRIBUTES

leap

NTP Leap Indicator. See CONSTANTS for more information.

version

NTP version.

mode

NTP mode. See CONSTANTS for more information.

stratum

NTP stratum. See CONSTANTS for more information.

poll

Maximum poll interval between messages in seconds to the nearest power of two.

precision

Precision of the local clock in seconds to the nearest power of two.

rootDelay

Total roundtrip delay to the primary reference source, in seconds with the fraction point between bits 15 and 16.

rootDisp

Maximum error relative to the primary reference source in seconds with the fraction point between bits 15 and 16.

refId

In the case of stratum 2 or greater, this is the IPv4 address of the primary reference host. In the case of stratum 0 or 1, this is a four byte, left-justified, zero padded ASCII string.

ref
ref_frac

The local time at which the local clock was last set or corrected and the fractional part.

org
org_frac

The local time when the client sent the request and the fractional part.

rec
rec_frac

The local time when the request was received by the server and the fractional part.

xmt
xmt_frac

The local time when the reply was sent from the server and the fractional part.

The following are inherited attributes. See Net::Frame::Layer for more information.

raw
payload
nextLayer

METHODS

new
new (hash)

Object constructor. You can pass attributes that will overwrite default ones. See SYNOPSIS for default values.

The following are inherited methods. Some of them may be overriden in this layer, and some others may not be meaningful in this layer. See Net::Frame::Layer for more information.

layer
computeLengths
pack
unpack
encapsulate
getLength
getPayloadLength
print
dump

USEFUL SUBROUTINES

Load them: use Net::Frame::Layer::NTP qw(:subs);

ntpTimestamp (time)

Create an NTP-adjusted timestamp.

ntp2date (time, frac)

Provided the NTP time and fracional timestamps, returns a human-readable time string.

CONSTANTS

Load them: use Net::Frame::Layer::NTP qw(:consts);

NF_NTP_ADJ

NTP adjustment (2208988800).

NF_NTP_LI_NOWARN
NF_NTP_LI_61
NF_NTP_LI_59
NF_NTP_LI_ALARM

NTP leap indicators.

NF_NTP_MODE_RSVD
NF_NTP_MODE_SYMACTIVE
NF_NTP_MODE_SYMPASSIVE
NF_NTP_MODE_CLIENT
NF_NTP_MODE_SERVER
NF_NTP_MODE_BROADCAST
NF_NTP_MODE_NTPCONTROL
NF_NTP_MODE_PRIVATE

NTP modes.

NF_NTP_STRATUM_UNSPEC
NF_NTP_STRATUM_PRIMARY
NF_NTP_STRATUM_UNSYNC

NTP stratums.

NF_NTP_REFID_GOES
NF_NTP_REFID_GPS
NF_NTP_REFID_GAL
NF_NTP_REFID_PPS
NF_NTP_REFID_IRIG
NF_NTP_REFID_WWVB
NF_NTP_REFID_DCF
NF_NTP_REFID_HBG
NF_NTP_REFID_MSF
NF_NTP_REFID_JJY
NF_NTP_REFID_LORC
NF_NTP_REFID_TDF
NF_NTP_REFID_CHU
NF_NTP_REFID_WWV
NF_NTP_REFID_WWVH
NF_NTP_REFID_NIST
NF_NTP_REFID_ACTS
NF_NTP_REFID_USNO
NF_NTP_REFID_PTB

NTP reference ID codes.

NF_NTP_KoD_ACST
NF_NTP_KoD_AUTH
NF_NTP_KoD_AUTO
NF_NTP_KoD_BCST
NF_NTP_KoD_CRYP
NF_NTP_KoD_DENY
NF_NTP_KoD_DROP
NF_NTP_KoD_RSTR
NF_NTP_KoD_INIT
NF_NTP_KoD_MCST
NF_NTP_KoD_NKEY
NF_NTP_KoD_RATE
NF_NTP_KoD_RMOT
NF_NTP_KoD_STEP

NTP kiss codes.

SEE ALSO

Net::Frame::Layer

AUTHOR

Michael Vincent

COPYRIGHT AND LICENSE

Copyright (c) 2016, Michael Vincent

You may distribute this module under the terms of the Artistic license. See LICENSE.Artistic file in the source distribution archive.