122724Sdist /*
234914Sbostic  * Copyright (c) 1983 Eric P. Allman
334047Sbostic  * Copyright (c) 1988 Regents of the University of California.
434047Sbostic  * All rights reserved.
534047Sbostic  *
6*42822Sbostic  * %sccs.include.redist.c%
734047Sbostic  *
834047Sbostic  */
922724Sdist 
1022724Sdist #ifndef lint
1122724Sdist char copyright[] =
1234047Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\
1322724Sdist  All rights reserved.\n";
1434047Sbostic #endif /* not lint */
1522724Sdist 
1622724Sdist #ifndef lint
17*42822Sbostic static char sccsid[] = "@(#)mailstats.c	5.7 (Berkeley) 06/01/90";
1834047Sbostic #endif /* not lint */
194379Seric 
2034047Sbostic #include <sys/file.h>
2134047Sbostic #include <sendmail.h>
2234047Sbostic #include <mailstats.h>
2337973Sbostic #include "pathnames.h"
244379Seric 
254379Seric main(argc, argv)
2634047Sbostic 	int argc;
2734047Sbostic 	char **argv;
284379Seric {
2934047Sbostic 	extern char *optarg;
3034047Sbostic 	extern int optind;
314379Seric 	struct statistics stat;
324379Seric 	register int i;
3334047Sbostic 	int ch, fd;
3434047Sbostic 	char *sfile, *ctime();
354379Seric 
3637973Sbostic 	sfile = _PATH_MAILSTATS;
3734047Sbostic 	while ((ch = getopt(argc, argv, "f:")) != EOF)
3834047Sbostic 		switch((char)ch) {
3934047Sbostic 		case 'f':
4034047Sbostic 			sfile = optarg;
4134047Sbostic 			break;
4234047Sbostic 		case '?':
4334047Sbostic 		default:
4434047Sbostic 			fputs("usage: mailstats [-f file]\n", stderr);
4534047Sbostic 			exit(EX_USAGE);
4634047Sbostic 		}
4734047Sbostic 	argc -= optind;
4834047Sbostic 	argv += optind;
4934047Sbostic 
5034047Sbostic 	if ((fd = open(sfile, O_RDONLY)) < 0) {
5134047Sbostic 		fputs("mailstats: ", stderr);
524379Seric 		perror(sfile);
534379Seric 		exit(EX_NOINPUT);
544379Seric 	}
5534047Sbostic 	if (read(fd, &stat, sizeof(stat)) != sizeof(stat) ||
5634047Sbostic 	    stat.stat_size != sizeof(stat)) {
5734047Sbostic 		fputs("mailstats: file size changed.\n", stderr);
584379Seric 		exit(EX_OSERR);
594379Seric 	}
604379Seric 
614380Seric 	printf("Statistics from %s", ctime(&stat.stat_itime));
624379Seric 	printf(" M msgsfr bytes_from  msgsto   bytes_to\n");
634379Seric 	for (i = 0; i < MAXMAILERS; i++)
6434047Sbostic 		if (stat.stat_nf[i] || stat.stat_nt[i])
6534047Sbostic 			printf("%2d %6ld %10ldK %6ld %10ldK\n", i,
6634047Sbostic 			    stat.stat_nf[i], stat.stat_bf[i],
6734047Sbostic 			    stat.stat_nt[i], stat.stat_bt[i]);
6834047Sbostic 	exit(0);
694379Seric }
70