jesper@diku.dk (Jesper L. Lauritsen) (04/15/91)
Does anybody have a RFC 868 time server for HP-UX (or some other unix with sockets)? Thanks in advance. --Jesper ------------------------------------------------------ Jesper L. Lauritsen, systems programmer Center for Applied Datalogy, University of Copenhagen Studiestraede 6, DK-1455 Copenhagen, Denmark Phone: +45 3312 0115 E-mail: jesper@vm.ibt.dk
barrett@Daisy.EE.UND.AC.ZA (Alan P. Barrett) (04/19/91)
In article <1991Apr15.140404.13179@odin.diku.dk>, jesper@diku.dk (Jesper L. Lauritsen) writes: > Does anybody have a RFC 868 time server for HP-UX (or some other unix with > sockets)? Here is something I wrote recently. It just sends four chars to stdout. If this program is invoked by the HP-UX inetd (via a suitable entry in inetd.conf), stdout should automatically be pointed to the right place, without your having to worry about it. --apb Alan Barrett, Dept. of Electronic Eng., Univ. of Natal, Durban, South Africa RFC822: barrett@ee.und.ac.za Bang: m2xenix!quagga!undeed!barrett # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Alan P Barrett <barrett@undeed> on Thu Apr 18 22:49:18 1991 # # This archive contains: # rfc868time.c # LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH echo x - rfc868time.c cat >rfc868time.c <<'@EOF' /* Outputs the number of seconds since 1 Jan 1900 00:00:00 UTC, * as a 32 bit number in network byte order. * See RFC868. */ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <time.h> #include <sys/types.h> #include <netinet/in.h> main (argc, argv) int argc; char **argv; { unsigned long ultime; /* ANSI says this will be at least 32 bits */ char chtime[4]; /* XXX: assumes that chars are 8 bits */ /* get time in seconds since 1970, and hence seconds since 1900 */ /* there were 2208988800 seconds between 1 Jan 1900 and 1 Jan 1970 */ ultime = 2208988800L + (unsigned long) time(NULL); /* convert to network byte order */ chtime[0] = (char) ((ultime>>24) & 0xff); chtime[1] = (char) ((ultime>>16) & 0xff); chtime[2] = (char) ((ultime>>8) & 0xff); chtime[3] = (char) (ultime & 0xff); /* XXX: lint says 'conversion from long may lose accuracy' on this line, but not on the preceding lines. Why? */ /* output result. */ /* XXX: hope that it all goes into one UDP packet, if we are being called * via UDP. */ if (write (1, chtime, 4) != 4) { (void) fprintf (stderr, "%s: write failed: %s\n", argv[0], strerror(errno)); exit (1); } exit (0); } @EOF chmod 644 rfc868time.c exit 0