On Sat, Oct 23, 1999 at 04:22:48PM -0400, Denis Voitenko wrote:
> > > 13 * * * * rdate your.isps.rdate.server >/dev/null 2>&1 && clock -w
>
> I could not find the rdate command on my Slackware 4. Where can I download
> the package? Freshmeat did not find it for me.
It's tiny, so here it is, as an attachment; I hope
the mailing-list system allows attachments.
Regards,
- Irving
-
[EMAIL PROTECTED] Happy Man Corporation
+1 206 463 9399, ext. 101 4410 SW Pt Robinson Rd
fax: +1 209 821 5439 Vashon, WA 98070 USA
Solid Value Investment Letter -- more than 14 years
safely outperforming the stock market through wise,
conservative selection: http://www.solid-value.com/
#ifndef lint
static char sccsid[] = "@(#)rdate.c 1.1 92/07/30";
#endif
/*
* Copyright (c) 1983 by Sun Microsystems, Inc.
*/
/*
* rdate - get date from remote machine
*
* sets time, obtaining value from host
* on the tcp/time socket. Since timeserver returns
* with time of day in seconds since Jan 1, 1900, must
* subtract 86400(365*70 + 17) to get time
* since Jan 1, 1970, which is what get/settimeofday
* uses.
*/
/* #define TOFFSET (86400*(365*70 + 17)) */
/*
* Some compilers complain if cast not included even if expr is
* being assigned to a long. Go figure...
*/
#define TOFFSET ((long)86400*(365*70 + 17))
/* original value was in 1983, so set sanity chk to a more recent value */
#define WRITTEN 891417600 /* tv_sec when built */
#include <signal.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
int timeout();
main(argc, argv)
int argc;
char **argv;
{
struct sockaddr_in server;
struct sockaddr from;
int s, i;
u_long time;
struct servent *sp;
struct protoent *pp;
struct hostent *hp;
struct timeval timestruct;
if (argc != 2) {
fprintf(stderr, "usage: rdate host\n");
exit(1);
}
if ((hp = gethostbyname(argv[1])) == NULL) {
fprintf(stderr, "Sorry, host %s not in hosts database\n",
argv[1]);
exit(1);
}
if ((sp = getservbyname("time", "tcp")) == NULL) {
fprintf(stderr,
"Sorry, time service not in services database\n");
exit(1);
}
if ((pp = getprotobyname("tcp")) == NULL) {
fprintf(stderr,
"Sorry, TCP protocol not in protocols database\n");
exit(1);
}
if ((s = socket(AF_INET, SOCK_STREAM, pp->p_proto)) == 0) {
perror("rdate: socket");
exit(1);
}
bzero((char *)&server, sizeof (server));
bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
server.sin_family = hp->h_addrtype;
server.sin_port = sp->s_port;
if (connect(s, &server, sizeof (server)) < 0) {
perror("rdate: connect");
exit(1);
}
alarm(10); /* perhaps this should be larger? */
signal(SIGALRM, timeout);
if (read(s, (char *)&time, sizeof (int)) != sizeof (int)) {
perror("rdate: read");
exit(1);
}
time = ntohl(time) - TOFFSET;
/* date must be later than when program was written */
if (time < WRITTEN) {
fprintf(stderr, "didn't get plausible time from %s\n",
argv[1]);
exit(1);
}
timestruct.tv_usec = 0;
timestruct.tv_sec = time;
i = settimeofday(×truct, 0);
if (i == -1)
perror("couldn't set time of day");
else
printf("%s", ctime(×truct.tv_sec));
exit(0);
/* NOTREACHED */
}
timeout()
{
fprintf(stderr, "couldn't contact time server\n");
exit(1);
}