<HTML ><HEAD ><TITLE >Gerd Knorr $B$5$s$K$h$k%9%K%U%!(B</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.54"><LINK REL="HOME" TITLE="Linux Infrared HOWTO" HREF="index.html"><LINK REL="UP" TITLE="$B%7%j%"%k@V30@~%]!<%H%9%K%U%!(B" HREF="infrared-howto-a-serial-ip-sniffers.html"><LINK REL="PREVIOUS" TITLE="$B%7%j%"%k@V30@~%]!<%H%9%K%U%!(B" HREF="infrared-howto-a-serial-ip-sniffers.html"><LINK REL="NEXT" TITLE="sersniff" HREF="infrared-howto-s-snersniff.html"></HEAD ><BODY CLASS="SECT1" BGCOLOR="#FFFFFF" TEXT="#000000" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Linux Infrared HOWTO</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="infrared-howto-a-serial-ip-sniffers.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" >Appendix C. $B%7%j%"%k@V30@~%]!<%H%9%K%U%!(B</TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="infrared-howto-s-snersniff.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="INFRARED-HOWTO-S-SNIFFER" >C.1. Gerd Knorr $B$5$s$K$h$k%9%K%U%!(B</A ></H1 ><P >$B$3$N%W%m%0%i%`$O(B Gerd Knorr $B$5$s$+$iDs6!$r<u$1$?$b$N$G$9!#(B $B$3$l$rMQ$$$F%W%m%H%3%k$N:YIt$r8+$k$?$a(B IrDA $B$rDL$7$F9T$o$l$kDL?.$rI=<($9$k$3$H$,$G$-$^$9(B ($B%=!<%9Cf$N(B ttyS1 $B$OI,MW$K1~$8$FJQ99$7$F$/$@$5$$(B)$B!#(B </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><FONT COLOR="#000000" ><PRE CLASS="PROGRAMLISTING" >#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <termios.h> #include <ctype.h> #include <sys/types.h> #include <sys/time.h> #include <sys/ioctl.h> #define BUFSIZE 1024 int read_and_print(int fd, int sec, int usec) { int rc,l,i; char buf[BUFSIZE+1]; fd_set set; struct timeval tv; if (sec || usec) { FD_ZERO(&set); FD_SET(fd,&set); tv.tv_sec = sec; tv.tv_usec = usec; if (0 == select(fd+1,&set,NULL,NULL,&tv)) return -1; } switch (rc = read(fd,buf,BUFSIZE)) { case 0: printf("EOF"); exit(0); break; case -1: perror("read"); exit(1); default: for (l = 0; l < rc; l+= 16) { printf("%04x ",l); for (i = l; i < l+16; i++) { if (i < rc) printf("%02x ",buf[i]); else printf("-- "); if ((i%4) == 3) printf(" "); } for (i = l; i < l+16; i++) { if (i < rc) printf("%c",isalnum(buf[i]) ? buf[i] : '.'); } printf("\n"); } break; } return rc; } void setlines(int fd, int rts, int dtr) { int lines = 0; if (rts) lines |= TIOCM_RTS; if (dtr) lines |= TIOCM_DTR; ioctl(fd,TIOCMSET,&lines); } int main(int argc, char *argv[]) { int ser,i; struct termios saved_attributes,tattr; struct winsize win; char buf[16]; if (-1 == (ser = open("/dev/ttyS1",O_RDWR))) { perror("open /dev/ttyS1"); exit(1); } /* Set the terminal mode */ tcgetattr (ser, &tattr); cfmakeraw (&tattr); cfsetospeed (&tattr,B9600); cfsetispeed (&tattr,B9600); tcsetattr (ser, 0, &tattr); setlines(ser,0,0); #if 0 tcsendbreak(ser,0); #endif /* main loop */ fprintf(stderr,"setup done\n"); while (-1 != read_and_print(ser,30,0)) { usleep(100000); } return 0; }</PRE ></FONT ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="infrared-howto-a-serial-ip-sniffers.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="infrared-howto-s-snersniff.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >$B%7%j%"%k@V30@~%]!<%H%9%K%U%!(B</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="infrared-howto-a-serial-ip-sniffers.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >sersniff</TD ></TR ></TABLE ></DIV ></BODY ></HTML >