The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::SNTP::Server - Perl Module SNTP Server based on RFC4330

VERSION

Version 0.06

SYNOPSIS

The Net::SNTP::Server - Perl module has the ability to reply to NTP or SNTP client queries towards the Server. The moment that the server is correctly initialized, it will wait for client requests on the IP and port defined by the user. The SNTP server uses the local clock to retrieve highest possible accuracy (seconds and nano seconds) in-order to calculate the round-trip delay d and system clock offset t. Accuracy may differ from one OS to the other. The server will encode the message and formated based on RFC4330 protocol specifications. The server will remain active until the user decides to terminate the connection.

    use Net::SNTP::Server;

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

ABSTRACT

The module retrieves and sends a UDP packet formated according to RFC4330 to a defined NTP or SNTP server sent by the Client. The received packet, gets decoded end encoded to be retransmitted back to the Client.

DESCRIPTION

This module exports a single method (basicSNTPSetup) and returns an associative hash output, based on the user input. In case of an error, the connection will be terminated and an error string will be printed with the possible cause.

The response from the SNTP server is been encoded to a human readable format. The obtained information received from the server on the client side can be used into further processing or manipulation according to the user needs. Maximum accuracy down to nano seconds can only be achieved based on different OS.

  • IP

        -ip: Is not a mandatory for the method key to operate correctly.
        By default the module will assign the localhost IP ("127.0.0.1"),
        but this will restrict the server to localhost communications (only
        internally it can receive and transmit data).
  • PORT

        -port: Is a mandatory key, that the user must define. By default the
        port is not set. The user has to specify the port. We can not use the
        default 123 NTP due to permission. The user has to choose a port number
        identical to port that the client will use client to communicate with
        the server (e.g. -port => 123456).

IMPORTANT NOTES

Different OS, different precision abilities. In order the user to gain the most out of this module, the script should be executed in Linux-wise OS. Ofcourse the module can operate correctly on all OS but due to OS accuracy limitations and internal OS restrictions we need to have administrator authority to access these data. For more information see Windows Time Service Registry Entries.

Given in consideration of the information that we explained why the user should execute the module on Linux, Fedora, Redhat etc. We reccomend to Install the ntp package. the NTP package if you want to use the server as primary time synchronization source and you want the daemon to run in the background continuously to automatically synchronize your internal OS clock. By installing the NTP package, the user can benefit from the ntpd daemon and extract all the useful extra information from the Server. In case the user does not want to install the NTP package the SNTP Server can provide all the information that the Client requires.

The module has been tested on LinuxOS and WindowsOS but it should be compatible with MacOS as well, but it has not been tested, not yet at least.

SUBROUTINES/METHODS

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

basicSNTPSetup

  my %hashInput = (
      -ip      => "127.0.0.1", # IP
      -port    => 12345,       # Default NTP locked port 123
      );

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

This module exports a single method (basicSNTPSetup) and returns an associative hash output, based on the user input. In case of an error, the connection will be terminated and an error string will be printed with the possible cause.

The response from the SNTP server is been encoded to a human readable format. The obtained information received from the server on the client side can be used into further processing or manipulation according to the user needs. Maximum accuracy down to nano seconds can only be achieved based on different OS.

EXAMPLE

This example starts a remote SNTP server based on RFC4330 message format. IP and Port need to be provided on the start up based on user preference.

We use the Data::Dumper module to print the error output in case of faulty initiliazation. The module does not require to printout the output. It should be used only for initialization purposes to assist the user with debugging in case of an error. The $error string it is also optional that will assist the user to identify the root that can cause a faulty initialization.

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

  use Net::SNTP::Server qw(basicSNTPSetup);

  my %hashInput = (
      -ip      => "127.0.0.1",
      -port    => 12345,
      );

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

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

AUTHOR

Athanasios Garyfalos, <garyfalos at cpan.org>

BUGS

Please report any bugs or feature requests to bug-net-sntp-server at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-SNTP-Server. 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::Server

You can also look for information at:

SEE ALSO

perl, IO::Socket, Net::SNTP::Client, 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-Server

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

I want to say thank you to Perl Monks The Monastery Gates for their guidance and assistance when ever I had a problem with the implementation process of module.

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: Server.pm,v $ Revision 6.0 2015/10/09 12:13:31 pm Thanos