Commit | Line | Data |
---|---|---|
16f092bf | 1 | /* implogd.c 4.2 82/10/10 */ |
6046cba1 SL |
2 | |
3 | #include <time.h> | |
4 | #include <sgtty.h> | |
5 | #include <sys/types.h> | |
6 | #include <sys/socket.h> | |
7 | #include <net/in.h> | |
8 | ||
9 | #define LOGFILE "/usr/adm/implog" | |
10 | #define IMPMTU ((8159 / 8) & ~01) | |
11 | ||
12 | u_char request[1024]; | |
13 | int marktime(); | |
14 | int options; | |
15 | extern int errno; | |
16 | int log; | |
17 | ||
18 | /* | |
19 | * Socket address, internet style, with | |
20 | * unused space taken by timestamp and packet | |
21 | * size. | |
22 | */ | |
23 | struct sockstamp { | |
24 | short sin_family; | |
25 | u_short sin_port; | |
26 | struct in_addr sin_addr; | |
27 | time_t sin_time; | |
28 | int sin_cc; | |
29 | }; | |
30 | ||
31 | struct sockproto improto = { PF_IMPLINK, 0 }; | |
32 | struct sockstamp from; | |
33 | ||
34 | main(argc, argv) | |
35 | char *argv[]; | |
36 | { | |
37 | int s, cc; | |
38 | time_t t; | |
39 | ||
40 | argc--, argv++; | |
41 | if (argc > 0 && !strcmp(argv[0], "-d")) | |
42 | options |= SO_DEBUG; | |
16f092bf SL |
43 | #ifndef DEBUG |
44 | if (fork()) | |
45 | exit(0); | |
46 | for (s = 0; s < 10; s++) | |
47 | (void) close(t); | |
48 | (void) open("/", 0); | |
49 | (void) dup2(0, 1); | |
50 | (void) dup2(0, 2); | |
51 | { int tt = open("/dev/tty", 2); | |
52 | if (tt > 0) { | |
53 | ioctl(tt, TIOCNOTTY, 0); | |
54 | close(tt); | |
55 | } | |
6046cba1 | 56 | } |
16f092bf | 57 | #endif |
6046cba1 SL |
58 | log = open(LOGFILE, 1); |
59 | if (log < 0) | |
60 | exit(1); | |
61 | lseek(log, 0L, 2); | |
62 | from.sin_time = time(0); | |
63 | from.sin_cc = sizeof(time_t); | |
64 | write(log, (char *)&from, sizeof(from)); | |
65 | again: | |
66 | errno = 0; | |
67 | if ((s = socket(SOCK_RAW, &improto, 0, options)) < 0) { | |
68 | perror("socket"); | |
69 | sleep(5); | |
70 | goto again; | |
71 | } | |
72 | for (;;) { | |
73 | cc = receive(s, &from, request, sizeof(request)); | |
74 | if (cc <= 0) | |
75 | continue; | |
76 | if (cc > IMPMTU) /* sanity */ | |
77 | continue; | |
78 | from.sin_cc = cc; | |
79 | from.sin_time = time(0); | |
80 | write(log, (char *)&from, sizeof(from)); | |
81 | write(log, request, cc); | |
82 | } | |
83 | /*NOTREACHED*/ | |
84 | } |