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