[alt.sources.d] rdate

wnp@iiasa.ac.at (Wolf PAUL ) (12/01/90)

Is the source code for timed available, or is it proprietary?

If Sun's timed is proprietary, has anyone written a PD or
distributable program offering the same functionality?

Thanks for any and all info!

Wolf
--
W.N.Paul, Int. Institute f. Applied Systems Analysis, A-2361 Laxenburg--Austria
PHONE: +43-2236-71521-465            INTERNET: wnp%iiasa@relay.eu.net
FAX:   +43-2236-71313                UUCP:     uunet!iiasa!wnp
HOME:  +43-2236-618514               BITNET:   tuvie!iiasa!wnp@awiuni01.BITNET

geoff@hinode.East.Sun.COM (Geoff Arnold @ Sun BOS - R.H. coast near the top) (12/01/90)

Quoth wnp%iiasa@relay.eu.net (Wolf PAUL ) (in <978@iiasa.UUCP>):
#
#Is the source code for timed available, or is it proprietary?

It's available - here's the source corresponding to the
recently-posted binary. Note that this needs "unix2dos"ing...

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh to create the files:
#	rdate.c
# This archive created: Fri Nov 30 14:10:44 1990 by geoff, Sun Microsystems PC-NFS Engineering
#
#
export PATH; PATH=/bin:$PATH


if test -f rdate.c ; then
echo shar: will not over-write existing file rdate.c
else
echo shar: extracting rdate.c, 3812 characters
sed 's/^X//' > rdate.c <<'SHAR_EOF'
X/*
X *  rdate - get date from remote machine
X *
X *
X *     	"rdate" sets the date and time, obtaining a timestamp froma
X *	network host via the tcp/time socket.  Since this returns
X *	a value in seconds since Jan 1, 1900,  we must
X *	subtract 86400(365*70 + 17) to convert this to the time
X *	since Jan 1, 1970. (Note that to avoid Microsoft C 4.0
X *	compiler glitches we must compute this at run time.)
X *
X * This program is supplied as an example of how to use the PC-NFS
X * Programmer's Toolkit to port typical socket-based network applications
X * from Unix systems to PCs running PC-NFS and DOS. It is supplied
X * "as is" with no warranty or support.
X *
X * The binary (rdate.exe) was built using Microsoft C 4.0 and the
X * "medium model" Toolkit libraries using the following batch file:
X *
X * msc /AM /Ox /Ze rdate.c ;
X * echo rdate + > lf
X * echo ..\toolkit\tcpypobj\myp_rtns.obj ..\toolkit\tcpypobj\mprotrtn.obj >> lf
X * echo rdate.exe >> lf
X * echo rdate /m >> lf
X * echo ..\toolkit\mlibtk.lib >> lf
X * link /ST:16384 @lf
X *
X */
X
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <dos.h>
X#include <io.h>
X#include <string.h>
X#include <sys\nfs_time.h>
X#include <sys\types.h>
X#include <sys\socket.h>
X#include <netinet\in.h>
X#include <netdb.h>
X#include <tklib.h>
X
X
X
X/* Local Function Prototypes */
X
Xvoid main(int argc,char * *argv);
Xint setdostime(unsigned long t);
X
Xextern int errno;
X
Xvoid main(argc, argv)
X	int argc;
X	char **argv;
X{
X	struct sockaddr_in server;
X	int s, i, p, q;
X	u_long t;
X	u_long toff;
X	struct servent *sp;
X	struct protoent *pp;
X	struct hostent *hp;
X
X	if (argc != 2) {
X		fprintf(stderr, "usage: rdate host\n");
X		exit(1);
X	}
X	if ((hp = gethostbyname(argv[1])) == NULL) {
X		fprintf(stderr, "rdate: unknown host %s\n",
X		    argv[1]);
X		exit(1);
X	}
X	if ((sp = getservbyname("time", "tcp")) != NULL) 
X		p = sp->s_port;
X	else
X		p = htons(37); /* default from Assigned Numbers RFC */
X
X	if ((pp = getprotobyname("tcp")) != NULL) 
X		q = pp->p_proto;
X	else
X		q = 6; /* default from Assigned Numbers */
X
X	if ((s = socket(AF_INET, SOCK_STREAM, q)) == 0) {
X		perror("rdate: socket");
X		exit(1);
X	}
X
X	bzero((char *)&server, sizeof (server));
X	bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
X	server.sin_family = hp->h_addrtype;
X	server.sin_port = p;
X
X	if (connect(s, (struct sockaddr *)&server, sizeof (server)) < 0) {
X		perror("rdate: connect");
X		exit(1);
X	}
X	if (read(s, (char *)&t, sizeof (long)) != sizeof (long)) {
X		perror("rdate: read");
X		exit(1);
X	}
X	t = (u_long)ntohl(t);
X
X/* begin hack to avoid MSC problem */
X
X	toff = 86400L;
X	toff = toff * 25567L;
X/* end hack */
X
X	if (t < toff) {
X		fprintf(stderr, "rdate: %s returned an unreasonable time\n",
X		    argv[1]);
X		exit(1);
X	}
X
X	t -= toff;
X
X	i = setdostime(t);
X
X	if (i == -1)
X		perror("rdate: unable to set time of day");
X	else
X		printf("%s", ctime(&t));
X	exit(0);
X}
X
X
X/*
X * setdostime (t) sets the PC DOS date and time values according to
X * the timestamp in t. We first call "localtime" to obtain the
X * individual year, month, day, hour, minute and second values and
X * then use the DOS "set time" and "set date" functions. Note that
X * for "localtime" to operate properly, the "TZ" environment variable
X * must be correct.
X */
X
Xsetdostime(t)
Xu_long t;
X{
Xstruct tm *tp;
Xunion REGS inregs;
Xunion REGS outregs;
X
X	tp = localtime(&t);
X	inregs.h.ah = 0x2d; /* set time */
X	inregs.h.ch = (unsigned char)tp->tm_hour;
X	inregs.h.dh = (unsigned char)tp->tm_sec;
X	inregs.h.cl = (unsigned char)tp->tm_min;
X	inregs.h.dl = (unsigned char)0;
X	intdos(&inregs, &outregs);
X	if (outregs.h.al)
X		return(-1);
X
X	inregs.h.ah = 0x2b; /*set date */
X	inregs.x.cx = tp->tm_year + 1900;
X	inregs.h.dh = (unsigned char)tp->tm_mon + 1;
X	inregs.h.dl = (unsigned char)tp->tm_mday;
X	intdos(&inregs, &outregs);
X	if ((int)outregs.h.al)
X		return(-1);
X
X	return(0);
X}
SHAR_EOF
len=`wc -c < rdate.c`
if test $len != 3812 ; then
echo shar: rdate.c was $len bytes long, should have been 3812
fi
fi # end of overwriting check

exit 0
#	End of shell archive
-- Geoff Arnold, PC-NFS architect, Sun Microsystems. (geoff@East.Sun.COM)   --
   *** "Now is no time to speculate or hypothecate, but rather a time ***
   *** for action, or at least not a time to rule it out, though not  ***
   *** necessarily a time to rule it in, either." - George Bush       ***

wnp@iiasa.ac.at (Wolf PAUL ) (12/01/90)

In article <3484@jaytee.East.Sun.COM> geoff@east.sun.com (Geoff Arnold @ Sun BOS - R.H. coast near the top) writes:
>Quoth wnp%iiasa@relay.eu.net (Wolf PAUL ) (in <978@iiasa.UUCP>):
>#
>#Is the source code for timed available, or is it proprietary?
>
>It's available - here's the source corresponding to the
>recently-posted binary. Note that this needs "unix2dos"ing...
>
>#	rdate.c

Only problem is, I was asking for the source code to TIMED, i.e. the
server end which rdate talks to.

How about that?

And while we're at it, how about an "on" command for PC-NFS?

Thanks!
--
W.N.Paul, Int. Institute f. Applied Systems Analysis, A-2361 Laxenburg--Austria
PHONE: +43-2236-71521-465            INTERNET: wnp%iiasa@relay.eu.net
FAX:   +43-2236-71313                UUCP:     uunet!iiasa!wnp
HOME:  +43-2236-618514               BITNET:   tuvie!iiasa!wnp@awiuni01.BITNET