1 /* 2 * Copyright (c) 1988 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * Sendmail 13 * Copyright (c) 1983 Eric P. Allman 14 * Berkeley, California 15 */ 16 17 #ifndef lint 18 char copyright[] = 19 "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 20 All rights reserved.\n"; 21 #endif /* not lint */ 22 23 #ifndef lint 24 static char sccsid[] = "@(#)mailstats.c 5.4 (Berkeley) 04/21/88"; 25 #endif /* not lint */ 26 27 #include <sys/file.h> 28 #include <sendmail.h> 29 #include <mailstats.h> 30 31 main(argc, argv) 32 int argc; 33 char **argv; 34 { 35 extern char *optarg; 36 extern int optind; 37 struct statistics stat; 38 register int i; 39 int ch, fd; 40 char *sfile, *ctime(); 41 42 sfile = "/usr/lib/sendmail.st"; 43 while ((ch = getopt(argc, argv, "f:")) != EOF) 44 switch((char)ch) { 45 case 'f': 46 sfile = optarg; 47 break; 48 case '?': 49 default: 50 fputs("usage: mailstats [-f file]\n", stderr); 51 exit(EX_USAGE); 52 } 53 argc -= optind; 54 argv += optind; 55 56 if ((fd = open(sfile, O_RDONLY)) < 0) { 57 fputs("mailstats: ", stderr); 58 perror(sfile); 59 exit(EX_NOINPUT); 60 } 61 if (read(fd, &stat, sizeof(stat)) != sizeof(stat) || 62 stat.stat_size != sizeof(stat)) { 63 fputs("mailstats: file size changed.\n", stderr); 64 exit(EX_OSERR); 65 } 66 67 printf("Statistics from %s", ctime(&stat.stat_itime)); 68 printf(" M msgsfr bytes_from msgsto bytes_to\n"); 69 for (i = 0; i < MAXMAILERS; i++) 70 if (stat.stat_nf[i] || stat.stat_nt[i]) 71 printf("%2d %6ld %10ldK %6ld %10ldK\n", i, 72 stat.stat_nf[i], stat.stat_bf[i], 73 stat.stat_nt[i], stat.stat_bt[i]); 74 exit(0); 75 } 76