122724Sdist /*
234914Sbostic  * Copyright (c) 1983 Eric P. Allman
334047Sbostic  * Copyright (c) 1988 Regents of the University of California.
434047Sbostic  * All rights reserved.
534047Sbostic  *
634047Sbostic  * Redistribution and use in source and binary forms are permitted
734914Sbostic  * provided that the above copyright notice and this paragraph are
834914Sbostic  * duplicated in all such forms and that any documentation,
934914Sbostic  * advertising materials, and other materials related to such
1034914Sbostic  * distribution and use acknowledge that the software was developed
1134914Sbostic  * by the University of California, Berkeley.  The name of the
1234914Sbostic  * University may not be used to endorse or promote products derived
1334914Sbostic  * from this software without specific prior written permission.
1434914Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1534914Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1634914Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1734047Sbostic  *
1834047Sbostic  */
1922724Sdist 
2022724Sdist #ifndef lint
2122724Sdist char copyright[] =
2234047Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\
2322724Sdist  All rights reserved.\n";
2434047Sbostic #endif /* not lint */
2522724Sdist 
2622724Sdist #ifndef lint
27*37973Sbostic static char sccsid[] = "@(#)mailstats.c	5.6 (Berkeley) 05/11/89";
2834047Sbostic #endif /* not lint */
294379Seric 
3034047Sbostic #include <sys/file.h>
3134047Sbostic #include <sendmail.h>
3234047Sbostic #include <mailstats.h>
33*37973Sbostic #include "pathnames.h"
344379Seric 
354379Seric main(argc, argv)
3634047Sbostic 	int argc;
3734047Sbostic 	char **argv;
384379Seric {
3934047Sbostic 	extern char *optarg;
4034047Sbostic 	extern int optind;
414379Seric 	struct statistics stat;
424379Seric 	register int i;
4334047Sbostic 	int ch, fd;
4434047Sbostic 	char *sfile, *ctime();
454379Seric 
46*37973Sbostic 	sfile = _PATH_MAILSTATS;
4734047Sbostic 	while ((ch = getopt(argc, argv, "f:")) != EOF)
4834047Sbostic 		switch((char)ch) {
4934047Sbostic 		case 'f':
5034047Sbostic 			sfile = optarg;
5134047Sbostic 			break;
5234047Sbostic 		case '?':
5334047Sbostic 		default:
5434047Sbostic 			fputs("usage: mailstats [-f file]\n", stderr);
5534047Sbostic 			exit(EX_USAGE);
5634047Sbostic 		}
5734047Sbostic 	argc -= optind;
5834047Sbostic 	argv += optind;
5934047Sbostic 
6034047Sbostic 	if ((fd = open(sfile, O_RDONLY)) < 0) {
6134047Sbostic 		fputs("mailstats: ", stderr);
624379Seric 		perror(sfile);
634379Seric 		exit(EX_NOINPUT);
644379Seric 	}
6534047Sbostic 	if (read(fd, &stat, sizeof(stat)) != sizeof(stat) ||
6634047Sbostic 	    stat.stat_size != sizeof(stat)) {
6734047Sbostic 		fputs("mailstats: file size changed.\n", stderr);
684379Seric 		exit(EX_OSERR);
694379Seric 	}
704379Seric 
714380Seric 	printf("Statistics from %s", ctime(&stat.stat_itime));
724379Seric 	printf(" M msgsfr bytes_from  msgsto   bytes_to\n");
734379Seric 	for (i = 0; i < MAXMAILERS; i++)
7434047Sbostic 		if (stat.stat_nf[i] || stat.stat_nt[i])
7534047Sbostic 			printf("%2d %6ld %10ldK %6ld %10ldK\n", i,
7634047Sbostic 			    stat.stat_nf[i], stat.stat_bf[i],
7734047Sbostic 			    stat.stat_nt[i], stat.stat_bt[i]);
7834047Sbostic 	exit(0);
794379Seric }
80