*BSD News Article 95022


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!como.dpie.gov.au!news.gan.net.au!act.news.telstra.net!news.telstra.net!news.att.net.au!news.att.net.hk!newsgate.cuhk.edu.hk!hammer.uoregon.edu!ais.net!news-peer.sprintlink.net!news.sprintlink.net!Sprint!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: rdate for FreeBSD
Date: 8 May 1997 19:05:28 GMT
Organization: Private BSD site, Dresden
Lines: 67
Message-ID: <5kt85o$pig@uriah.heep.sax.de>
References: <9014106B902414DF.F2C1CE0DB63DC135.683F46B51D3A4FBF@library-proxy.airnews.net>
  <E9CL33.LM@sphynx.fdn.fr>
  <DB7ECA28AB48E25C.480A35112851C7DE.B4902F4E00C95599@library-proxy.airnews.net>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:40642

Phil Crown <pcrown@airmail.net> wrote:

> I started to download xntpd, but its over a meg and I think its an X
> app, I only need a simple utility to set the clock, preferrably non-X.

Others have already pointed out that it's not an X11 app.  Anyway, you
are aware that FreeBSD ships with xnptd by default, thus no need to
download it?

> Actually, I need to sync two computers, one in the CST and one in the
> EST.

That's unimportant.  Unlike a certain other, well not really operating
system, Unix didn't ignore the timezone issue from the beginning.  The
kernel clock always runs in UTC (aka. GMT), the interpretation of the
local timezone is handled in userland.  Of course, xntpd is
synchronizing kernel clocks.

> I may look at xntpd again, first I wanted to try rdate, then maybe
> timed.

``timed is the best method to have a collection of networked computers
slowly and continuously drifting away in time.'' :-)

(timed tries to synchronize machines on the ``average network time'',
and since your average network time will always be either slower or
faster than the real time, the machines will drift in the end.)

The problem with rdate is simply that it causes time `jumps'.  Many
utilities (e.g. cron) make the assumption however that the time will
always increase monotonically.

If you really think you need rdate, here is one.  It requires one
argument (the name of the remote host), will connect to that host's
`time' port (internal to inetd), fetch the date, and issue a local
date(1) command.  Most of the code gratuitously stolen from the Perl
IPC example in the man page. ;-)

#!/usr/bin/perl

die "usage: $0 remotehost\n" unless $#ARGV == 0;

require 'sys/socket.ph';
$sockaddr = 'S n a4 x8';

($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $port) = getservbyname('time', 'tcp');
($name, $aliases, $type, $len, $thataddr) = gethostbyname($ARGV[0]);

$that = pack($sockaddr, &AF_INET, $port, $thataddr);
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!";
connect(S, $that) || die "connect: $!";

read(S, $x, 4);
($time) = unpack(N, $x);
$time -= 25567 * 24*60*60;	# network time is seconds since 1900

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
system "date", sprintf("%02d%02d%02d%02d%02d.%02d", $year, $mon + 1, $mday,
		       $hour, $min, $sec);

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)