3 # Copyright (c) 1995 Graham Barr <Graham.Barr@tiuk.ti.com>. All rights
4 # reserved. This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
11 Net::Time - time and daytime network client interface
15 use Net::Time qw(inet_time inet_daytime);
17 print inet_time('localhost');
18 print inet_time('localhost', 'tcp');
20 print inet_daytime('localhost');
21 print inet_daytime('localhost', 'tcp');
25 C<Net::Time> provides subroutines that obtain the time on a remote machine.
29 =item inet_time ( HOST [, PROTOCOL])
31 Obtain the time on C<HOST> using the protocol as defined in RFC868. The
32 optional argument C<PROTOCOL> should define the protocol to use, either
33 C<tcp> or C<udp>. The result will be a unix-like time value or I<undef>
36 =item inet_daytime ( HOST [, PROTOCOL])
38 Obtain the time on C<HOST> using the protocol as defined in RFC867. The
39 optional argument C<PROTOCOL> should define the protocol to use, either
40 C<tcp> or C<udp>. The result will be an ASCII string or I<undef>
47 Graham Barr <Graham.Barr@tiuk.ti.com>
55 Copyright (c) 1995 Graham Barr. All rights reserved. This program is free
56 software; you can redistribute it and/or modify it under the same terms
62 use vars qw($VERSION @ISA @EXPORT_OK);
68 @EXPORT_OK = qw(inet_time inet_daytime);
70 $VERSION = sprintf("%d.%02d", q$Revision: 2.0 $ =~ /(\d+)\.(\d+)/);
74 my($pname,$pnum,$host,$proto) = @_;
78 my $port = (getservbyname($pname, $proto))[2] || $pnum;
80 my $me = IO::Socket::INET->new(PeerAddr => $host,
86 if(defined $me && $proto eq 'udp');
93 my $s = _socket('time',37,@_) || return undef;
96 # the time protocol return time in seconds since 1900, convert
97 # it to a unix time (seconds since 1970)
99 $s->recv($buf, length(pack("N",0))) ? (unpack("N",$buf))[0] - 2208988800
105 my $s = _socket('daytime',13,@_) || return undef;
108 $s->recv($buf, 1024) ? $buf