1 #ifndef lint 2 static char sccsid[] = "@(#)implogd.c 4.7 (Berkeley) 06/12/83"; 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, O_CREAT|O_WRONLY|O_APPEND, 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 fromlen = sizeof (from), len; 75 76 len = recvfrom(s, request, sizeof (request), 0, 77 &from, &fromlen); 78 if (len < 0) { 79 perror("implogd: recvfrom"); 80 continue; 81 } 82 if (len == 0 || len > IMPMTU) /* sanity */ 83 continue; 84 from.sin_len = len; 85 from.sin_time = time(0); 86 write(log, (char *)&from, sizeof (from)); 87 write(log, request, len); 88 } 89 /*NOTREACHED*/ 90 } 91