X-Git-Url: http://sjero.net/git/?p=ltp2tcp;a=blobdiff_plain;f=ltp2tcp.c;fp=ltp2tcp.c;h=db8e08866e89badc097cea5f0b3f3286db155c1c;hp=e0a63f08cb127259f8a96117b296fce5b2219443;hb=059a06a0a0ab5ae8e2e7f6fd80fcc3b13c438fb6;hpb=5a8bbcc78de4f63b7e22c9ea10e12748edca9d96 diff --git a/ltp2tcp.c b/ltp2tcp.c index e0a63f0..db8e088 100644 --- a/ltp2tcp.c +++ b/ltp2tcp.c @@ -28,7 +28,8 @@ Notes: ******************************************************************************/ #include "ltp2tcp.h" - +#define LTPTRACE_VERSION 0.3 +#define COPYRIGHT_YEAR 2013 int debug=0; int MAX_SESSION=500000; @@ -45,6 +46,8 @@ int handle_report(const u_char* odata, struct ltp_hdr_d* ltph, struct tcphdr *tc int claim2sack(const u_char* odata, int ses_id, struct ltp_hdr_d* ltph, struct tcphdr *tcph, u_char* tcpopt, int* dlen, int rbuf); int seq_from_session(struct ltp_hdr_d* ltph, struct tcphdr *tcph); int ack_from_session(struct ltp_hdr_d* ltph, struct tcphdr *tcph); +void version(); +void usage(); /*Parse commandline options and open files*/ @@ -59,28 +62,33 @@ int main(int argc, char *argv[]) int tmp; /*parse commandline options*/ - if(argc<4 || argc > 8){ - printf("Usage: ltp2tcp -t{encapsulation} ltp_file tcp_file [-d] [-b{block_size}]\n"); - exit(1); + if(argc < 2){ + usage(); } /*loop through commandline options*/ for(int i=1; i < argc; i++){ - if(argv[i][0]!='-'){ - if(lfile==NULL){ /*assign first non-dash argument to the ltp file*/ + if(argv[i][0]!='-' || (argv[i][0]=='-' && strlen(argv[i])==1)){ + if(lfile==NULL || argv[i][0]=='-'){ + /*assign first non-dash (or only dash) argument to the dccp file*/ lfile=argv[i]; }else{ if(tfile==NULL){ tfile=argv[i]; /*assign second non-dash argument to the dccp file*/ }else{ - printf("Usage: ltp2tcp -t{encapsulation} ltp_file tcp_file [-d] [-b{block_size}]\n"); - exit(1); + usage(); } } }else{ - if(argv[i][1]=='d' && strlen(argv[i])==2){ /*debug option*/ + if(argv[i][1]=='v' && strlen(argv[i])==2){ /*debug option*/ debug++; } + if(argv[i][1]=='V' && strlen(argv[i])==2){ /*Version option*/ + version(); + } + if(argv[i][1]=='h'&& strlen(argv[i])==2){ /* help*/ + usage(); + } if(argv[i][1]=='t'){ /*Encapsulation option*/ type=&argv[i][2]; } @@ -89,8 +97,7 @@ int main(int argc, char *argv[]) if(tmp>0){ MAX_SESSION=tmp; }else{ - printf("Usage: ltp2tcp -t{encapsulation} ltp_file tcp_file [-d] [-b{block_size}]\n"); - exit(1); + usage(); } } if(argv[i][1]=='s'){ /*Session range option*/ @@ -102,8 +109,7 @@ int main(int argc, char *argv[]) } if(lfile==NULL || tfile==NULL || type==NULL){ - printf("Usage: ltp2tcp -t{encapsulation} ltp_file tcp_file [-d] [-b{block_size}]\n"); - exit(1); + usage(); } if(state.ses_min<=0 || state.ses_max<=0){ @@ -114,7 +120,6 @@ int main(int argc, char *argv[]) /*all options validated*/ if(debug){ - dbgprintf(1,"Debug On\n"); dbgprintf(1,"Input file: %s\n", lfile); dbgprintf(1,"Output file: %s\n", tfile); dbgprintf(1,"Encapsulation: %s\n", type); @@ -895,6 +900,29 @@ int ack_from_session(struct ltp_hdr_d* ltph, struct tcphdr *tcph) return 0; } +void version() +{ + dbgprintf(0, "ltp2tcp version %.1f\n",LTPTRACE_VERSION); + dbgprintf(0, "Copyright (C) %i Samuel Jero \n",COPYRIGHT_YEAR); + dbgprintf(0, "This program comes with ABSOLUTELY NO WARRANTY.\n"); + dbgprintf(0, "This is free software, and you are welcome to\n"); + dbgprintf(0, "redistribute it under certain conditions.\n"); + exit(0); +} + +/*Usage information for program*/ +void usage() +{ + dbgprintf(0,"Usage: ltp2tcp -t{encapsulation} [-v] [-V] [-h] [-b{block_size}] [-s{start session}-{end session}] ltp_file tcp_file\n"); + dbgprintf(0, " -v verbose. May be repeated for additional verbosity.\n"); + dbgprintf(0, " -V Version information\n"); + dbgprintf(0, " -h Help\n"); + dbgprintf(0, " -t type of encapsulation (udp,dccp,sll)\n"); + dbgprintf(0, " -b LTP block size (NOT the bundle size) that is being used over this connection\n"); + dbgprintf(0, " -s Requests a graph of only the specified range of sessions\n"); + exit(0); +} + /*Debug Printf*/ void dbgprintf(int level, const char *fmt, ...) {