Commit | Line | Data |
---|---|---|
19538291 | 1 | /* |
b8c620d6 | 2 | * Copyright (c) 1983, 1988 Regents of the University of California. |
df2b70fd MK |
3 | * All rights reserved. |
4 | * | |
32ce521f | 5 | * %sccs.include.redist.c% |
19538291 DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
9 | char copyright[] = | |
b8c620d6 | 10 | "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ |
19538291 | 11 | All rights reserved.\n"; |
b8c620d6 | 12 | #endif /* not lint */ |
19538291 | 13 | |
28b5b7e7 | 14 | #ifndef lint |
32ce521f | 15 | static char sccsid[] = "@(#)implogd.c 5.9 (Berkeley) %G%"; |
b8c620d6 | 16 | #endif /* not lint */ |
6046cba1 | 17 | |
fdaa1466 | 18 | #include <sys/param.h> |
ac4316d8 | 19 | #include <sys/time.h> |
6046cba1 | 20 | #include <sys/socket.h> |
18148cbb | 21 | #include <sys/syslog.h> |
fdaa1466 | 22 | #include <sys/file.h> |
56013160 | 23 | |
ae92ba7a MK |
24 | #include <net/if.h> |
25 | ||
56013160 | 26 | #include <netinet/in.h> |
fdaa1466 | 27 | #include <netimp/if_imp.h> |
6046cba1 | 28 | |
ac4316d8 KB |
29 | #include <sgtty.h> |
30 | #include "pathnames.h" | |
6046cba1 SL |
31 | |
32 | /* | |
33 | * Socket address, internet style, with | |
34 | * unused space taken by timestamp and packet | |
35 | * size. | |
36 | */ | |
37 | struct sockstamp { | |
38 | short sin_family; | |
39 | u_short sin_port; | |
40 | struct in_addr sin_addr; | |
41 | time_t sin_time; | |
56013160 | 42 | int sin_len; |
6046cba1 SL |
43 | }; |
44 | ||
ac4316d8 | 45 | main() |
6046cba1 | 46 | { |
ac4316d8 | 47 | register int len, log, s; |
56013160 | 48 | struct sockstamp from; |
ac4316d8 KB |
49 | int fromlen; |
50 | u_char request[1024]; | |
51 | time_t time(); | |
6046cba1 | 52 | |
ac4316d8 KB |
53 | openlog("implogd", LOG_PID|LOG_ODELAY|LOG_PERROR, LOG_DAEMON); |
54 | log = open(_PATH_IMPLOG, O_CREAT|O_WRONLY|O_APPEND, 0644); | |
28026947 | 55 | if (log < 0) { |
ac4316d8 | 56 | syslog(LOG_ERR, "%s: %m\n", _PATH_IMPLOG); |
28026947 MK |
57 | exit(1); |
58 | } | |
ac4316d8 KB |
59 | from.sin_time = time((time_t *)NULL); |
60 | from.sin_len = sizeof(time_t); | |
61 | (void)write(log, (char *)&from, sizeof(from)); | |
28026947 | 62 | if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) { |
18148cbb | 63 | syslog(LOG_ERR, "socket: %m\n"); |
ac4316d8 | 64 | exit(1); |
28026947 | 65 | } |
16f092bf | 66 | #ifndef DEBUG |
ac4316d8 KB |
67 | { |
68 | register int i, tt; | |
69 | ||
70 | if (fork()) | |
71 | exit(0); | |
72 | for (i = 0; i < 10; i++) | |
73 | if (i != log && i != s) | |
74 | (void) close(i); | |
75 | (void) open("/", O_RDONLY, 0); | |
76 | (void) dup2(0, 1); | |
77 | (void) dup2(0, 2); | |
7abf8d65 | 78 | tt = open(_PATH_TTY, O_RDWR, 0); |
ac4316d8 KB |
79 | if (tt > 0) { |
80 | ioctl(tt, TIOCNOTTY, 0); | |
81 | (void)close(tt); | |
82 | } | |
6046cba1 | 83 | } |
16f092bf | 84 | #endif |
ac4316d8 KB |
85 | for (fromlen = sizeof(from);;) { |
86 | len = recvfrom(s, request, sizeof(request), 0, | |
87 | &from, &fromlen); | |
fecd8ea3 | 88 | if (len < 0) { |
18148cbb | 89 | syslog(LOG_ERR, "recvfrom: %m\n"); |
6046cba1 | 90 | continue; |
fdaa1466 | 91 | } |
ac4316d8 | 92 | if (len == 0 || len > IMPMTU) /* sanity */ |
6046cba1 | 93 | continue; |
56013160 | 94 | from.sin_len = len; |
ac4316d8 KB |
95 | from.sin_time = time((time_t *)NULL); |
96 | (void)write(log, (char *)&from, sizeof(from)); | |
97 | (void)write(log, request, len); | |
6046cba1 SL |
98 | } |
99 | /*NOTREACHED*/ | |
100 | } |