Athanasios Garyfalos

NAME

Net::SNTP::Client - Perl module to calculate the roundtrip delay d and system clock offset t from NTP or SNTP Server.

VERSION

Version 0.23

SYNOPSIS

The Net::SNTP::Client - Perl module retrieves the time from an NTP or SNTP server and uses the local time to calculate the roundtrip delay d and system clock offset t based on RFC4330. The module is calculating with higher accuracy in comparison to other modules.

    use Net::SNTP::Client qw ( getSNTPTime );

    my ( $error , $hashRefOutput ) = getSNTPTime( %hashInput );
    ...

ABSTRACT

The module sends a UDP packet formated according to RFC4330 to a defined NTP or SNTP server set by the user. The received packet, gets decoded to a human readable form and also calculated the roundtrip delay d and system clock offset t, based on the decoded data.

DESCRIPTION

This module exports a single method (getSNTPTime) and returns an associative hash of hashes upon RFC4330 and a string in case of an error occurs. The response from the NTP or SNTP server is beeen decoded to a human readable format. The obtained information recieved from the server can be can be used into further processing or manipulation according to the user needs. Maximum accuracy down to nano seconds can only be achieved on LinuxOS.

  • HOSTNAME

        -hostname: The mandatory key inorder the method to produce
        an output is only the hostname, the rest of the keys are optional.
  • PORT

        -port: By default the the port is set to 123 (NTP default port).
        The user has the option to overwite the port based on the expected
        NTP port on the server side (e.g. -port => 123456).
  • TIMEOUT

        -timeOut: By default the time out is set to 10 seconds. The user
        has the option to overwite the time out input option based on the
        expected connection time (e.g. timeOut => 15).
  • RFC4330 OUTPUT

        -RFC4330: This is an optional way to produce an easy visual
        output based on RFC4330 documentation. Expected input is a string,
        integer or boolean in the form (0 or 1).
  • CLEARSCREEN

        -clearScreen: This is an optional choice based on user preference
        if he/she desires to clear the "terminal screen" before printing
        the captured data. Expected input is a string, integer or boolean
        in the form (0 or 1).

SUBROUTINES/METHODS

  my ( $error , $hashRefOutput ) = getSNTPTime( %hashInput );

getSNTPTime

  my %hashInput = (
      -hostname      => $hostname,    # hostnmae or IP
      -port          => $port,        # default NTP port 123
      -timeOut       => $timeOut,     # default 10
      -RFC4330       => $RFC4330,     # default 0
      -clearScreen   => $clearScreen, # default 0
      );

  my ( $error , $hashRefOutput ) = getSNTPTime( %hashInput );

This module exports a single method - getSNTPTime and an error string in case of an error or a faulty operation. It expects a hash as an input. The input can have four different hash keys (-hostname, port, RFC4330 and -clearScreen).

EXAMPLE

This example gets the time from a remote NTP server from the pool.ntp.org: public ntp time server for everyone and calculates the roundtrip delay d and local clock offset t as defined on RFC4330.

We use the Data::Dumper module to print the output.

  #!/usr/bin/perl
  use strict;
  use warnings;
  use Data::Dumper;

  use Net::SNTP::Client;

  my %hashInput = (
      -hostname      => "0.pool.ntp.org",
      -port          => 123,
      -timeOut       => 10,
      -RFC4330       => 1,
      -clearScreen   => 1,
      );

  my ( $error , $hashRefOutput ) = getSNTPTime( %hashInput );

  print Dumper $hashRefOutput;
  print "Error: $error\n" if ($error);

DEPENDENCIES

The module is implemented using IO::Socket::INET and Time::HiRes and requires both these modules to be installed.

AUTHOR

Athanasios Garyfalos, <garyfalos at cpan.org>

BUGS

Please report any bugs or feature requests to bug-net-sntp-client at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-SNTP-Client. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::SNTP::Client

You can also look for information at:

SEE ALSO

perl, IO::Socket, Net::NTP, Net::SNTP::Server, RFC4330

Net::NTP has a similar focus as this module. In my opinion it is less accurate when it comes to the precission bellow second(s).

REPOSITORY

https://github.com/thanos1983/perl5-Net-SNTP-Client

DIFFERENCES FROM OTHER MODULES

Based on the current known modules Net::SNTP::Client is only similar to Net::NTP module. The two modules do not have in common the encoding and decoding process of fractions of seconds.

Be aware that on different OS different precision can be achieved.

DIFFERENCES BETWEEN NTP AND SNTP

SNTP (Simple Network Time Protocol) and NTP (Network Time Protocol) are describing exactly the same network package format, the differences can be found in the way how a system deals with the content of these packages in order to synchronize its time.

ACKNOWLEDGEMENTS

The original concept for this module was based on NTP.pm written by James G. Willmore <willmorejg@gmail.com>.

Copyright 2004 by James G. Willmore

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

LICENSE AND COPYRIGHT

Copyright 2015 Athanasios Garyfalos.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

CHANGE LOG $Log: Client.pm,v $ Revision 23.0 2019/31/10 7:01:21 pm Thanos