xref: /csrg-svn/old/implogd/implogd.c (revision 9198)
1*9198Ssam #ifndef lint
2*9198Ssam static char sccsid[] = "@(#)implogd.c	4.4 (Berkeley) 11/14/82";
3*9198Ssam #endif
46480Ssam 
56480Ssam #include <time.h>
66480Ssam #include <sgtty.h>
79196Ssam 
86480Ssam #include <sys/types.h>
96480Ssam #include <sys/socket.h>
106480Ssam 
119196Ssam #include <netinet/in.h>
129196Ssam 
136480Ssam #define	LOGFILE	"/usr/adm/implog"
146480Ssam #define	IMPMTU	((8159 / 8) & ~01)
156480Ssam 
166480Ssam u_char	request[1024];
176480Ssam int	marktime();
186480Ssam int	options;
196480Ssam extern	int errno;
206480Ssam int	log;
216480Ssam 
226480Ssam /*
236480Ssam  * Socket address, internet style, with
246480Ssam  * unused space taken by timestamp and packet
256480Ssam  * size.
266480Ssam  */
276480Ssam struct sockstamp {
286480Ssam 	short	sin_family;
296480Ssam 	u_short	sin_port;
306480Ssam 	struct	in_addr sin_addr;
316480Ssam 	time_t	sin_time;
329196Ssam 	int	sin_len;
336480Ssam };
346480Ssam 
356480Ssam main(argc, argv)
366480Ssam 	char *argv[];
376480Ssam {
389196Ssam 	int s;
396480Ssam 	time_t t;
409196Ssam 	struct sockstamp from;
416480Ssam 
426480Ssam 	argc--, argv++;
436480Ssam 	if (argc > 0 && !strcmp(argv[0], "-d"))
446480Ssam 		options |= SO_DEBUG;
458457Ssam #ifndef DEBUG
468457Ssam 	if (fork())
478457Ssam 		exit(0);
488457Ssam 	for (s = 0; s < 10; s++)
498457Ssam 		(void) close(t);
508457Ssam 	(void) open("/", 0);
518457Ssam 	(void) dup2(0, 1);
528457Ssam 	(void) dup2(0, 2);
538457Ssam 	{ int tt = open("/dev/tty", 2);
548457Ssam 	  if (tt > 0) {
558457Ssam 		ioctl(tt, TIOCNOTTY, 0);
568457Ssam 		close(tt);
578457Ssam 	  }
586480Ssam 	}
598457Ssam #endif
606480Ssam 	log = open(LOGFILE, 1);
616480Ssam 	if (log < 0)
626480Ssam 		exit(1);
636480Ssam 	lseek(log, 0L, 2);
646480Ssam 	from.sin_time = time(0);
659196Ssam 	from.sin_len = sizeof (time_t);
669196Ssam 	write(log, (char *)&from, sizeof (from));
676480Ssam again:
689196Ssam 	s = socket(AF_IMPLINK, SOCK_RAW, 0, 0);
699196Ssam 	if (s < 0) {
706480Ssam 		perror("socket");
716480Ssam 		sleep(5);
726480Ssam 		goto again;
736480Ssam 	}
746480Ssam 	for (;;) {
759196Ssam 		int len = sizeof (request);
769196Ssam 
779196Ssam 		if (recvfrom(s, request, &len, &from, sizeof (from), 0) < 0)
786480Ssam 			continue;
799196Ssam 		if (len <= 0 || len > IMPMTU)	/* sanity */
806480Ssam 			continue;
819196Ssam 		from.sin_len = len;
826480Ssam 		from.sin_time = time(0);
839196Ssam 		write(log, (char *)&from, sizeof (from));
849196Ssam 		write(log, request, len);
856480Ssam 	}
866480Ssam 	/*NOTREACHED*/
876480Ssam }
88