30#include <linux/ttytap.h>
31#include <linux/kdev_t.h>
34 fprintf(stderr,
"usage: ttytap -q|<ttyDevice>\n");
38int main(
int argc,
char **argv) {
48 unsigned char buf[4096];
53 if (strcmp(argv[1],
"-q")) {
54 if (stat(argv[1], &stbuf)) {
58 if (!S_ISCHR(stbuf.st_mode)) {
59 fprintf(stderr,
"%s is not a char device\n", argv[1]);
62 major = MAJOR(stbuf.st_rdev);
63 minor = MINOR(stbuf.st_rdev);
68 fd = open(
"/proc/ttytap", O_RDONLY);
70 perror(
"/proc/ttytap");
73 if (ioctl(fd, TTYTAP_SETDEV, (major << 8) | minor)) {
74 perror(
"ioctl /proc/ttytap");
77 if ((minor == 0) && (major == 0)) {
78 printf(
"Serial tapping switched off\n");
81 if (ioctl(fd, TTYTAP_GETQLEN, &i)) {
82 perror(
"ioctl /proc/ttytap");
85 fprintf(stderr,
"Queue length is %d\n", i);
87 r = read(fd, &th,
sizeof(th));
88 if (
r !=
sizeof(th)) {
89 perror(
"read /proc/ttytap");
92 strftime(tbuf, 255,
"%H:%M:%S", localtime(&th.stamp.tv_sec));
93 printf(
"%s.%06ld %c (%04d) ", tbuf,
94 (
unsigned long)th.stamp.tv_usec,
95 (th.io) ?
'<' :
'>', th.len);
96 r = read(fd, buf, th.len);
98 perror(
"read /proc/ttytap");
101 for (i = 0; i < th.len; i++)
102 printf(
"%02x ", buf[i] & 255);
103 for (i = 0; i < th.len; i++)
104 printf(
"%c", isprint(buf[i]) ? buf[i] :
'.');
105 printf(
"\n"); fflush(stdout);
int main(int argc, char **argv)