/*======================================================================
                    I N E T R A Y . K I L L . C 
                    doc: Thu Mar  5 12:24:52 1992
                    dlm: Tue Jul 20 17:20:10 1993
                    (c) 1992 ant@julia
                    uE-Info: 16 0 T 0 0 72 2 2 8 ofnI
======================================================================*/

#include	<stdio.h>
#include	<fcntl.h>
#include	<rpc/rpc.h>
#include	<sys/param.h>
#include	"inetray.h"
#include	"config.h"
#include	"common.h"
#include	"comm.h"
#include	"version.h"
#include	"patchlevel.h"

int	key;

main(ac,av)
int ac; char *av[];
{
	int	fd;
	char	buf[64];
	
	fprintf(stderr,"%s [%s%d]\n",av[0],VERSION,PATCHLEVEL);
	readRc();				/* read .rc file */
	if (ac > 1) {				/* get correct key */
		key = atoi(av[1]);
	} else {
		fd = open(KEYFILE,O_RDONLY);
		if (fd < 0) {
			fprintf(stderr,"No key supplied!\n");
			exit(1);
		}
		if (read(fd,buf,64) < 0) {
			perror("read keyfile");
			exit(1);
		}
		close(fd);
		sscanf(buf,"%ld",&key);
	}
	fprintf(stderr,"Using Session Key <%ld>\n",key);
	IRbroadcast(TERMINATE,xdr_int,&key);	/* done, exit, terminate, ... */
	sleep(RTIMEOUT);
	exit(0);
}
