From 94f2747ecb2178a5d0f36226675213a224bee84d Mon Sep 17 00:00:00 2001 From: Peter Baker Date: Tue, 28 Jun 2011 21:18:26 -0700 Subject: [PATCH] Add -z option to ignore EOF character rather than exiting. --- sersniff.8 | 6 +++++- sersniff.c | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sersniff.8 b/sersniff.8 index 97d012e..1714cff 100644 --- a/sersniff.8 +++ b/sersniff.8 @@ -19,7 +19,7 @@ sersniff \- a program to tunnel/sniff between 2 serial ports .SH SYNOPSIS .B sersniff -.RI [-h] [-i DEVICE ] [-o DEVICE] [-b BAUD] [-s] [-n] [-w USECS] +.RI [-h] [-i DEVICE ] [-o DEVICE] [-b BAUD] [-s] [-n] [-w USECS] [-z] .SH DESCRIPTION This manual page explains how to use the .B sersniff @@ -63,6 +63,10 @@ How many microsecs to wait before reporting a delay .TP .B \-x Show hex characters instead of normal ASCII characters. +.TP +.B \-z +Don't quit when an EOF character is received. +.TP .B \-f Specify the format string that should be used to print hex characters. .SH AUTHOR diff --git a/sersniff.c b/sersniff.c index 45572dc..bb6664f 100644 --- a/sersniff.c +++ b/sersniff.c @@ -4,6 +4,7 @@ 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 @@ -23,6 +24,7 @@ 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" @@ -126,7 +128,7 @@ void outputchar(unsigned char c, int port, int alpha, 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 rc; @@ -179,7 +181,7 @@ void mainloop(int port1, int port2, int silent, int alpha, long usec_threshold, timediff=0; if (!silent) write(port2,&c1,1); } - if (rc==0) { + if (rc==0 && quit_on_eof==1) { /* EOF? */ quit=1; } @@ -196,7 +198,7 @@ void mainloop(int port1, int port2, int silent, int alpha, long usec_threshold, timediff=0; if (!silent) write(port1,&c2,1); } - if (rc==0) { + if (rc==0 && quit_on_eof==1) { /* EOF? */ quit=1; } @@ -246,6 +248,7 @@ void usage() " (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); } @@ -266,9 +269,10 @@ int main(int argc, char *argv[]) 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(); @@ -327,6 +331,9 @@ int main(int argc, char *argv[]) case 'f': format=strdup(optarg); break; + case 'z': + quit_on_eof=0; + break; } } @@ -358,7 +365,7 @@ int main(int argc, char *argv[]) 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); -- 2.39.2