can't reset it if not set up
[unix-history] / usr / src / old / implogd / implogd.c
CommitLineData
19538291
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8char copyright[] =
9"@(#) Copyright (c) 1983 Regents of the University of California.\n\
10 All rights reserved.\n";
11#endif not lint
12
28b5b7e7 13#ifndef lint
18148cbb 14static char sccsid[] = "@(#)implogd.c 5.3 (Berkeley) %G%";
19538291 15#endif not lint
6046cba1 16
6046cba1 17#include <sgtty.h>
56013160 18
e2feeea9 19#include <sys/time.h>
fdaa1466 20#include <sys/param.h>
6046cba1 21#include <sys/socket.h>
18148cbb 22#include <sys/syslog.h>
fdaa1466 23#include <sys/file.h>
56013160
SL
24
25#include <netinet/in.h>
fdaa1466 26#include <netimp/if_imp.h>
6046cba1
SL
27
28#define LOGFILE "/usr/adm/implog"
6046cba1
SL
29
30u_char request[1024];
31int marktime();
32int options;
33extern int errno;
34int log;
35
36/*
37 * Socket address, internet style, with
38 * unused space taken by timestamp and packet
39 * size.
40 */
41struct sockstamp {
42 short sin_family;
43 u_short sin_port;
44 struct in_addr sin_addr;
45 time_t sin_time;
56013160 46 int sin_len;
6046cba1
SL
47};
48
6046cba1
SL
49main(argc, argv)
50 char *argv[];
51{
18148cbb 52 int i, s;
6046cba1 53 time_t t;
56013160 54 struct sockstamp from;
6046cba1
SL
55
56 argc--, argv++;
18148cbb 57 openlog("implogd", LOG_PID | LOG_ODELAY, LOG_DAEMON);
6046cba1
SL
58 if (argc > 0 && !strcmp(argv[0], "-d"))
59 options |= SO_DEBUG;
28026947
MK
60 log = open(LOGFILE, O_CREAT|O_WRONLY|O_APPEND, 0644);
61 if (log < 0) {
18148cbb 62 syslog(LOG_ERR, "%s: %m\n", LOGFILE);
28026947
MK
63 perror("implogd: open");
64 exit(1);
65 }
66 from.sin_time = time(0);
67 from.sin_len = sizeof (time_t);
68 write(log, (char *)&from, sizeof (from));
69 if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) {
18148cbb 70 syslog(LOG_ERR, "socket: %m\n");
28026947
MK
71 perror("implogd: socket");
72 exit(5);
73 }
16f092bf
SL
74#ifndef DEBUG
75 if (fork())
76 exit(0);
18148cbb
MK
77 for (i = 0; i < 10; i++)
78 if (i != log && i != s)
79 (void) close(i);
16f092bf
SL
80 (void) open("/", 0);
81 (void) dup2(0, 1);
82 (void) dup2(0, 2);
83 { int tt = open("/dev/tty", 2);
84 if (tt > 0) {
85 ioctl(tt, TIOCNOTTY, 0);
86 close(tt);
87 }
6046cba1 88 }
16f092bf 89#endif
6046cba1 90 for (;;) {
fecd8ea3 91 int fromlen = sizeof (from), len;
56013160 92
fecd8ea3
SL
93 len = recvfrom(s, request, sizeof (request), 0,
94 &from, &fromlen);
95 if (len < 0) {
18148cbb 96 syslog(LOG_ERR, "recvfrom: %m\n");
fdaa1466 97 perror("implogd: recvfrom");
6046cba1 98 continue;
fdaa1466 99 }
fecd8ea3 100 if (len == 0 || len > IMPMTU) /* sanity */
6046cba1 101 continue;
56013160 102 from.sin_len = len;
6046cba1 103 from.sin_time = time(0);
56013160
SL
104 write(log, (char *)&from, sizeof (from));
105 write(log, request, len);
6046cba1
SL
106 }
107 /*NOTREACHED*/
108}