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(
      li             => NF_NTP_LI_NOWARN,
      version        => 3,
      mode           => NF_NTP_MODE_CLIENT,
      stratum        => NF_NTP_STRATUM_UNSPEC,
      pollInterval   => 0,
      precision      => 0,
      rootDelay      => 0,
      rootDispersion => 0,
      refClockId     => 0,
      refTimestamp   => 0,
      refTimestamp_frac  => 0,
      origTimestamp      => 0,
      origTimestamp_frac => 0,
      recvTimestamp      => 0,
      recvTimestamp_frac => 0,
      xmitTimestamp      => ntpTimestamp(time),
      xmitTimestamp_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

li

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.

pollInterval

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.

rootDispersion

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

refClockId

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.

refTimestamp
refTimestamp_frac

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

origTimestamp
origTimestamp_frac

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

recvTimestamp
recvTimestamp_frac

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

xmitTimestamp
xmitTimestamp_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

NTP stratums.

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.