working out the protocol between a Nokia 9000i and NServer.
Written by Jonathan McDowell for Project Purple, 1999
Extra stuff by Cornelius Cook (cook@cpoint.net), 1999
+ OSX support and EOF support by Pete Baker (peteb4ker@gmail.com), 2011
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
07/09/1999 - Started writing.
21Nov1999 - Cook: added command line support and extra error checking
27Nov1999 - Cook: added select, timer & changed output look
+ 24Jun2011 - Baker: Added OSX support. Added EOF character support
*/
-#define VERSION "0.0.4"
+#define VERSION "0.0.5"
#include <stdio.h>
#include <string.h>
if (setup) {
bzero(&serparams, sizeof(serparams));
-
- serparams.c_cflag=baud | CLOCAL | CS8 | CREAD;
+
+ cfsetspeed(&serparams, baud);
+ serparams.c_cflag |= CLOCAL | CS8 | CREAD;
if (tcflush(filedes, TCIFLUSH)) {
fprintf(stderr,"%s: ",device);
disp_outputstr(port, todisplay, usec_threshold, usec_waited, name1, name2);
}
-void mainloop(int port1, int port2, int silent, int alpha, long usec_threshold, char *name1, char *name2, char *format)
+void mainloop(int port1, int port2, int silent, int alpha, int quit_on_eof, long usec_threshold, char *name1, char *name2, char *format)
{
unsigned char c1, c2;
- int last;
int rc;
fd_set rfds;
fd_set efds;
/* need the largest fd for the select call */
biggestfd=port1 > port2 ? port1 : port2;
biggestfd++;
- last=0;
while (!quit) {
/* reset the select set */
timediff=0;
if (!silent) write(port2,&c1,1);
}
- if (rc==0) {
+ if (rc==0 && quit_on_eof==1) {
/* EOF? */
quit=1;
}
timediff=0;
if (!silent) write(port1,&c2,1);
}
- if (rc==0) {
+ if (rc==0 && quit_on_eof==1) {
/* EOF? */
quit=1;
}
void usage()
{
- fprintf(stderr,"sersniff v%s
-
-Usage:
-sersniff [-h] [-i DEV | -l PORT] [-o DEV | -c HOST:PORT] [-b BAUD] [-w USEC]
--h This help
--x Show hex characters instead of alpha
--f PRINTF_OPTS printf style options for printing hex characters
- when '-x' switch is given (default \"<%%02hX>\")
--i DEVICE Port 1 device (defaults to /dev/ttyS0). Use host:port for
- TCP.
--1 PORT1_NAME Port 1 name to be printed (defaults to 'Port1')
--o DEVICE Port 2 device (defaults to /dev/ttyS1). Use :port for TCP.
--2 PORT2_NAME Port 2 name to be printed (defaults to 'Port2')
--b BAUD Baud rate (Defaults to 19200)
--n No port configuration (do not set BAUD or change settings)
--w USECS How many microsecs to wait before reporting a delay
- (default is %d)
--s Silent - don't pass data from port1 <=> port2,
- just display what we see from them.
-",VERSION,USEC);
+ fprintf(stderr,"sersniff v%s\n"
+
+"Usage:\n"
+"sersniff [-h] [-i DEV | -l PORT] [-o DEV | -c HOST:PORT] [-b BAUD] [-w USEC]\n"
+"-h This help\n"
+"-x Show hex characters instead of alpha\n"
+"-f PRINTF_OPTS printf style options for printing hex characters\n"
+" when '-x' switch is given (default \"<%%02hX>\")\n"
+"-i DEVICE Port 1 device (defaults to /dev/ttyS0). Use host:port for\n"
+" TCP.\n"
+"-1 PORT1_NAME Port 1 name to be printed (defaults to 'Port1')\n"
+"-o DEVICE Port 2 device (defaults to /dev/ttyS1). Use :port for TCP.\n"
+"-2 PORT2_NAME Port 2 name to be printed (defaults to 'Port2')\n"
+"-b BAUD Baud rate (Defaults to 19200)\n"
+"-n No port configuration (do not set BAUD or change settings)\n"
+"-w USECS How many microsecs to wait before reporting a delay\n"
+" (default is %d)\n"
+"-s Silent - don't pass data from port1 <=> port2,\n"
+" just display what we see from them.\n"
+"-z Don't quit when an EOF character is received.\n"
+,VERSION,USEC);
exit(1);
}
int silent=0;
long usec_threshold=USEC;
int setup_port=1;
+ int quit_on_eof=1;
char *format=NULL;
- while ((optret=getopt(argc,argv,"hxsni:l:o:c:b:w:1:2:f:"))!=EOF) {
+ while ((optret=getopt(argc,argv,"hxsnzi:l:o:c:b:w:1:2:f:"))!=EOF) {
switch (optret) {
case '?': case 'h': case ':':
usage();
case 'f':
format=strdup(optarg);
break;
+ case 'z':
+ quit_on_eof=0;
+ break;
}
}
exit(1);
}
- mainloop(port1, port2, silent, show_alpha, usec_threshold, name1, name2, format);
+ mainloop(port1, port2, silent, show_alpha, quit_on_eof, usec_threshold, name1, name2, format);
/* Clean up */
if (dev1) free(dev1);