Commit | Line | Data |
---|---|---|
28b5b7e7 | 1 | #ifndef lint |
e2feeea9 | 2 | static char sccsid[] = "@(#)implogd.c 4.8 (Berkeley) %G%"; |
28b5b7e7 | 3 | #endif |
6046cba1 | 4 | |
6046cba1 | 5 | #include <sgtty.h> |
56013160 | 6 | |
e2feeea9 | 7 | #include <sys/time.h> |
fdaa1466 | 8 | #include <sys/param.h> |
6046cba1 | 9 | #include <sys/socket.h> |
fdaa1466 | 10 | #include <sys/file.h> |
56013160 SL |
11 | |
12 | #include <netinet/in.h> | |
fdaa1466 | 13 | #include <netimp/if_imp.h> |
6046cba1 SL |
14 | |
15 | #define LOGFILE "/usr/adm/implog" | |
6046cba1 SL |
16 | |
17 | u_char request[1024]; | |
18 | int marktime(); | |
19 | int options; | |
20 | extern int errno; | |
21 | int log; | |
22 | ||
23 | /* | |
24 | * Socket address, internet style, with | |
25 | * unused space taken by timestamp and packet | |
26 | * size. | |
27 | */ | |
28 | struct sockstamp { | |
29 | short sin_family; | |
30 | u_short sin_port; | |
31 | struct in_addr sin_addr; | |
32 | time_t sin_time; | |
56013160 | 33 | int sin_len; |
6046cba1 SL |
34 | }; |
35 | ||
6046cba1 SL |
36 | main(argc, argv) |
37 | char *argv[]; | |
38 | { | |
56013160 | 39 | int s; |
6046cba1 | 40 | time_t t; |
56013160 | 41 | struct sockstamp from; |
6046cba1 SL |
42 | |
43 | argc--, argv++; | |
44 | if (argc > 0 && !strcmp(argv[0], "-d")) | |
45 | options |= SO_DEBUG; | |
16f092bf SL |
46 | #ifndef DEBUG |
47 | if (fork()) | |
48 | exit(0); | |
49 | for (s = 0; s < 10; s++) | |
50 | (void) close(t); | |
51 | (void) open("/", 0); | |
52 | (void) dup2(0, 1); | |
53 | (void) dup2(0, 2); | |
54 | { int tt = open("/dev/tty", 2); | |
55 | if (tt > 0) { | |
56 | ioctl(tt, TIOCNOTTY, 0); | |
57 | close(tt); | |
58 | } | |
6046cba1 | 59 | } |
16f092bf | 60 | #endif |
ce5e9df4 | 61 | log = open(LOGFILE, O_CREAT|O_WRONLY|O_APPEND, 0644); |
fdaa1466 SL |
62 | if (log < 0) { |
63 | perror("implogd: open"); | |
6046cba1 | 64 | exit(1); |
fdaa1466 | 65 | } |
6046cba1 | 66 | from.sin_time = time(0); |
56013160 SL |
67 | from.sin_len = sizeof (time_t); |
68 | write(log, (char *)&from, sizeof (from)); | |
fdaa1466 SL |
69 | while ((s = socket(AF_IMPLINK, SOCK_RAW, 0, 0)) < 0) { |
70 | perror("implogd: socket"); | |
6046cba1 | 71 | sleep(5); |
6046cba1 SL |
72 | } |
73 | for (;;) { | |
fecd8ea3 | 74 | int fromlen = sizeof (from), len; |
56013160 | 75 | |
fecd8ea3 SL |
76 | len = recvfrom(s, request, sizeof (request), 0, |
77 | &from, &fromlen); | |
78 | if (len < 0) { | |
fdaa1466 | 79 | perror("implogd: recvfrom"); |
6046cba1 | 80 | continue; |
fdaa1466 | 81 | } |
fecd8ea3 | 82 | if (len == 0 || len > IMPMTU) /* sanity */ |
6046cba1 | 83 | continue; |
56013160 | 84 | from.sin_len = len; |
6046cba1 | 85 | from.sin_time = time(0); |
56013160 SL |
86 | write(log, (char *)&from, sizeof (from)); |
87 | write(log, request, len); | |
6046cba1 SL |
88 | } |
89 | /*NOTREACHED*/ | |
90 | } |