1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988 Regents of the University of California.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms are permitted
7  * provided that the above copyright notice and this paragraph are
8  * duplicated in all such forms and that any documentation,
9  * advertising materials, and other materials related to such
10  * distribution and use acknowledge that the software was developed
11  * by the University of California, Berkeley.  The name of the
12  * University may not be used to endorse or promote products derived
13  * from this software without specific prior written permission.
14  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  */
19 
20 #ifndef lint
21 char copyright[] =
22 "@(#) Copyright (c) 1988 Regents of the University of California.\n\
23  All rights reserved.\n";
24 #endif /* not lint */
25 
26 #ifndef lint
27 static char sccsid[] = "@(#)mailstats.c	5.6 (Berkeley) 05/11/89";
28 #endif /* not lint */
29 
30 #include <sys/file.h>
31 #include <sendmail.h>
32 #include <mailstats.h>
33 #include "pathnames.h"
34 
35 main(argc, argv)
36 	int argc;
37 	char **argv;
38 {
39 	extern char *optarg;
40 	extern int optind;
41 	struct statistics stat;
42 	register int i;
43 	int ch, fd;
44 	char *sfile, *ctime();
45 
46 	sfile = _PATH_MAILSTATS;
47 	while ((ch = getopt(argc, argv, "f:")) != EOF)
48 		switch((char)ch) {
49 		case 'f':
50 			sfile = optarg;
51 			break;
52 		case '?':
53 		default:
54 			fputs("usage: mailstats [-f file]\n", stderr);
55 			exit(EX_USAGE);
56 		}
57 	argc -= optind;
58 	argv += optind;
59 
60 	if ((fd = open(sfile, O_RDONLY)) < 0) {
61 		fputs("mailstats: ", stderr);
62 		perror(sfile);
63 		exit(EX_NOINPUT);
64 	}
65 	if (read(fd, &stat, sizeof(stat)) != sizeof(stat) ||
66 	    stat.stat_size != sizeof(stat)) {
67 		fputs("mailstats: file size changed.\n", stderr);
68 		exit(EX_OSERR);
69 	}
70 
71 	printf("Statistics from %s", ctime(&stat.stat_itime));
72 	printf(" M msgsfr bytes_from  msgsto   bytes_to\n");
73 	for (i = 0; i < MAXMAILERS; i++)
74 		if (stat.stat_nf[i] || stat.stat_nt[i])
75 			printf("%2d %6ld %10ldK %6ld %10ldK\n", i,
76 			    stat.stat_nf[i], stat.stat_bf[i],
77 			    stat.stat_nt[i], stat.stat_bt[i]);
78 	exit(0);
79 }
80