19198Ssam #ifndef lint 2*9251Ssam static char sccsid[] = "@(#)implogd.c 4.5 (Berkeley) 11/15/82"; 39198Ssam #endif 46480Ssam 56480Ssam #include <time.h> 66480Ssam #include <sgtty.h> 79196Ssam 8*9251Ssam #include <sys/param.h> 96480Ssam #include <sys/socket.h> 10*9251Ssam #include <sys/file.h> 116480Ssam 129196Ssam #include <netinet/in.h> 13*9251Ssam #include <netimp/if_imp.h> 149196Ssam 156480Ssam #define LOGFILE "/usr/adm/implog" 166480Ssam 176480Ssam u_char request[1024]; 186480Ssam int marktime(); 196480Ssam int options; 206480Ssam extern int errno; 216480Ssam int log; 226480Ssam 236480Ssam /* 246480Ssam * Socket address, internet style, with 256480Ssam * unused space taken by timestamp and packet 266480Ssam * size. 276480Ssam */ 286480Ssam struct sockstamp { 296480Ssam short sin_family; 306480Ssam u_short sin_port; 316480Ssam struct in_addr sin_addr; 326480Ssam time_t sin_time; 339196Ssam int sin_len; 346480Ssam }; 356480Ssam 366480Ssam main(argc, argv) 376480Ssam char *argv[]; 386480Ssam { 399196Ssam int s; 406480Ssam time_t t; 419196Ssam struct sockstamp from; 426480Ssam 436480Ssam argc--, argv++; 446480Ssam if (argc > 0 && !strcmp(argv[0], "-d")) 456480Ssam options |= SO_DEBUG; 468457Ssam #ifndef DEBUG 478457Ssam if (fork()) 488457Ssam exit(0); 498457Ssam for (s = 0; s < 10; s++) 508457Ssam (void) close(t); 518457Ssam (void) open("/", 0); 528457Ssam (void) dup2(0, 1); 538457Ssam (void) dup2(0, 2); 548457Ssam { int tt = open("/dev/tty", 2); 558457Ssam if (tt > 0) { 568457Ssam ioctl(tt, TIOCNOTTY, 0); 578457Ssam close(tt); 588457Ssam } 596480Ssam } 608457Ssam #endif 61*9251Ssam log = open(LOGFILE, FCREATE|FWRONLY|FAPPEND, 0644); 62*9251Ssam if (log < 0) { 63*9251Ssam perror("implogd: open"); 646480Ssam exit(1); 65*9251Ssam } 666480Ssam from.sin_time = time(0); 679196Ssam from.sin_len = sizeof (time_t); 689196Ssam write(log, (char *)&from, sizeof (from)); 69*9251Ssam while ((s = socket(AF_IMPLINK, SOCK_RAW, 0, 0)) < 0) { 70*9251Ssam perror("implogd: socket"); 716480Ssam sleep(5); 726480Ssam } 736480Ssam for (;;) { 749196Ssam int len = sizeof (request); 759196Ssam 76*9251Ssam if (recvfrom(s, request, &len, 0, &from, sizeof (from)) < 0) { 77*9251Ssam perror("implogd: recvfrom"); 786480Ssam continue; 79*9251Ssam } 809196Ssam if (len <= 0 || len > IMPMTU) /* sanity */ 816480Ssam continue; 829196Ssam from.sin_len = len; 836480Ssam from.sin_time = time(0); 849196Ssam write(log, (char *)&from, sizeof (from)); 859196Ssam write(log, request, len); 866480Ssam } 876480Ssam /*NOTREACHED*/ 886480Ssam } 89