/* timesrvd.c -- time server daemon
 * R.E. Schmidt, US NAVAL OBSERVATORY, Washington, DC
 * March 1992
 *
 * This program provides a service called "timesrv".
 * In order for it to function, an entry for it needs to
 * exist in the local /etc/services file:
 *
 * timesrv   22375/tcp
 *
 * timesrv stream tcp  nowait  root /usr/local/bin/timesrv timesrv
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>

#ifdef AMIGA
  #include <stdlib.h>
#endif

#define LEN     sizeof(long)

void main(argc, argv)
  int argc;
  char *argv[];
{
  auto long tsecs, xcode = 1;
  auto time_t time();

  /* get time from my own system clock:
   */
  time(&tsecs);

  /* Send time back to the client.
   */
  if (send(0, (unsigned char const *) &tsecs, LEN, 0) == LEN)
    xcode = 0;

  shutdown(0, 2);

  exit(xcode);
}
