syncstat.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Display synchronous serial line statistics
*/
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ser_sync.h>
#include <libdlpi.h>
#define MAXWAIT 15
static void usage(void);
/*
* errstr is MAXPATHLEN + 11; 11 = 10 for "syncstat: " + null
*/
static int fd;
int
{
int len;
char *cp;
int do_clear = 0;
int period = 0;
int count;
if (argc == 1) {
usage();
exit(1);
}
argc--; /* skip the command name */
argv++;
/*
* The following loop processes command line arguments.
* If the argument begins with a '-', it is trated as an option.
* The only option currently implemented is "-c" (clears statistics).
* If the argument begins with a numeral, it is treated as an interval.
* Intervals must be positive integers greater than zero.
* Any argument that survives this is treated as a device name to be
* found under /dev.
*/
while (argc > 0) {
if (argv[0][0] == '-') {
if (argc == 1) {
usage();
exit(1);
}
usage();
exit(1);
}
do_clear = 1;
if (period == 0) {
"syncstat: bad interval: %s\n", *argv);
exit(1);
}
} else {
"syncstat: invalid device name "
"(too long) %s\n", *argv);
exit(1);
}
}
argc--;
argv++;
}
"syncstat: %s missing minor device number\n", ifname);
exit(1);
}
if (fd < 0) {
exit(1);
}
perror("syncstat: dlpi_attach");
exit(1);
}
perror("S_IOCGETMODE");
"syncstat: can't get sync mode info for %s\n",
ifname);
exit(1);
}
if (do_clear) {
perror("S_IOCCLRSTATS");
"syncstat: can't clear stats for %s\n",
ifname);
exit(1);
}
}
perror("S_IOCGETSTATS");
ifname);
exit(1);
}
if (period) {
if (sm.sm_baudrate == 0) {
exit(1);
}
}
}
(void) printf(
" speed ipkts opkts undrun ovrrun abort crc isize osize\n");
(void) printf(" %7d %7d %7d %7d %7d %7d %7d %7d %7d\n",
return (0);
}
static void
{
perror("S_IOCGETSTATS");
ifname);
exit(1);
}
" ipkts opkts undrun ovrrun abort crc iutil outil\n");
(void) printf(" %7d %7d %7d %7d %7d %7d %6d%% %6d%%\n",
}
static void
usage()
{
"Usage: syncstat [-c] device [period]");
}