Serial-over-network and serial-serial redirector+sniffer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

73 lines
1.8 KiB

/*
Copyright (C) 2006 AbsoluteValue Systems, Inc. All Rights Reserved.
Originally written and maintained by: Solomon Peachy <pizza@shaftnet.org>
Local redirection & Debugging code by: Mark Mathews <mark@linux-wlan.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/serial.h>
int main(int argc, char **argv) {
int fd;
int i;
int rval = 0;
char *devname;
struct serial_icounter_struct stats;
if (argc != 2) {
fprintf(stderr, "usage: serialstats devicename\n");
rval = 1;
goto done;
}
devname = argv[1];
fd = open(devname, O_RDWR|O_NONBLOCK|O_NOCTTY);
if (fd <= 0) {
perror("couldn't open device");
rval = fd;
goto done;
}
i = ioctl(fd, TIOCGICOUNT, &stats);
if (i != 0) {
perror("couldn't issue ioctl");
rval = i;
goto done;
}
printf("cts=%d\ndsr=%d\nrng=%d\ndcd=%d\nrx=%d\ntx=%d\nframe=%d\noverrun=%d\nparity=%d\nbrk=%d\nbuf_overrun=%d\n",
stats.cts, stats.dsr, stats.rng, stats.dcd,
stats.rx, stats.tx,
stats.frame, stats.overrun, stats.parity, stats.brk,
stats.buf_overrun);
close(fd);
done:
return rval;
}