1 #ifndef lint 2 static char sccsid[] = "@(#)implogd.c 4.5 (Berkeley) 11/15/82"; 3 #endif 4 5 #include <time.h> 6 #include <sgtty.h> 7 8 #include <sys/param.h> 9 #include <sys/socket.h> 10 #include <sys/file.h> 11 12 #include <netinet/in.h> 13 #include <netimp/if_imp.h> 14 15 #define LOGFILE "/usr/adm/implog" 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; 33 int sin_len; 34 }; 35 36 main(argc, argv) 37 char *argv[]; 38 { 39 int s; 40 time_t t; 41 struct sockstamp from; 42 43 argc--, argv++; 44 if (argc > 0 && !strcmp(argv[0], "-d")) 45 options |= SO_DEBUG; 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 } 59 } 60 #endif 61 log = open(LOGFILE, FCREATE|FWRONLY|FAPPEND, 0644); 62 if (log < 0) { 63 perror("implogd: open"); 64 exit(1); 65 } 66 from.sin_time = time(0); 67 from.sin_len = sizeof (time_t); 68 write(log, (char *)&from, sizeof (from)); 69 while ((s = socket(AF_IMPLINK, SOCK_RAW, 0, 0)) < 0) { 70 perror("implogd: socket"); 71 sleep(5); 72 } 73 for (;;) { 74 int len = sizeof (request); 75 76 if (recvfrom(s, request, &len, 0, &from, sizeof (from)) < 0) { 77 perror("implogd: recvfrom"); 78 continue; 79 } 80 if (len <= 0 || len > IMPMTU) /* sanity */ 81 continue; 82 from.sin_len = len; 83 from.sin_time = time(0); 84 write(log, (char *)&from, sizeof (from)); 85 write(log, request, len); 86 } 87 /*NOTREACHED*/ 88 } 89