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