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