From 54e1f22a80114111c40ba5f047f5bceb76b69c6e Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Mon, 26 Jan 2009 02:04:25 +0000 Subject: [PATCH] Merged in fwknop-c-ubuntu branch changes via: svn merge -r 39:40 svn+ssh://rohan/usr/local/svn/fwknop-c/branches/fwknop-c-ubuntu This merge includes the following: -Started on command line argument processing with getopt_long(). For now this just handles --help and --version, and there is a new cmdl_opts typedef for setting and storing option data. git-svn-id: file:///home/mbr/svn/fwknop/trunk@44 510a4753-2344-4c79-9c09-4d669213fbeb --- src/fwknop.c | 90 +++++++++++++++++++++++++++++++++++++++++++++------- src/fwknop.h | 50 +++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 src/fwknop.h diff --git a/src/fwknop.c b/src/fwknop.c index 148ffb9d..4c06e768 100644 --- a/src/fwknop.c +++ b/src/fwknop.c @@ -23,12 +23,14 @@ * ***************************************************************************** */ -#include -#include -#include "fko.h" -void display_ctx(fko_ctx_t ctx); -void hex_dump(unsigned char *data, int size); +/* includes */ +#include "fwknop.h" + +static void display_ctx(fko_ctx_t ctx); +static void hex_dump(unsigned char *data, int size); +static void process_cmd_line(cmdl_opts *options, int argc, char **argv); +static void usage(void); #define FKO_PW "BubbaWasHere" @@ -37,6 +39,11 @@ main(int argc, char **argv) { fko_ctx_t ctx, ctx2; int res; + cmdl_opts options; + + /* Handle command line + */ + process_cmd_line(&options, argc, argv); /* Intialize the context */ @@ -81,10 +88,11 @@ main(int argc, char **argv) res = fko_spa_data_final(ctx, FKO_PW); if(res != FKO_SUCCESS) fprintf(stderr, "Error #%i from fko_spa_data_final: %s\n", res, fko_errstr(res)); - + /* Display the context data. */ - display_ctx(ctx); + if (! options.quiet) + display_ctx(ctx); /************** Decoding now *****************/ @@ -102,16 +110,18 @@ main(int argc, char **argv) fprintf(stderr, "Error #%i from fko_decrypt_spa_data: %s\n", res, fko_errstr(res)); */ - printf("\nDump of the Decoded Data\n"); - display_ctx(ctx2); + if (! options.quiet) { + printf("\nDump of the Decoded Data\n"); + display_ctx(ctx2); + } fko_destroy(ctx); fko_destroy(ctx2); return(0); -} +} -void +static void display_ctx(fko_ctx_t ctx) { printf("\nFKO Context Values:\n===================\n\n"); @@ -149,7 +159,7 @@ display_ctx(fko_ctx_t ctx) } -void +static void hex_dump(unsigned char *data, int size) { int ln, i, j = 0; @@ -184,4 +194,60 @@ hex_dump(unsigned char *data, int size) } } +static void process_cmd_line(cmdl_opts *options, int argc, char **argv) +{ + int getopt_c = 0; + int opt_index = 0; + + memset(options, 0x00, sizeof(cmdl_opts)); + + while (1) { + opt_index = 0; + static struct option long_options[] = { + {"quiet", 0, NULL, 'q'}, + {"verbose", 0, NULL, 'v'}, + {"Version", 0, NULL, 'V'}, + {"help", 0, NULL, 'h'}, + {0, 0, 0, 0} + }; + getopt_c = getopt_long(argc, argv, "qhvV", + long_options, &opt_index); + if (getopt_c == -1) + break; + + switch (getopt_c) { + case 'q': + options->quiet = 1; + break; + case 'v': + options->verbose = 1; + break; + case 'V': + fprintf(stdout, "[+] fwknop-%s\n", FWKNOP_VERSION); + exit(0); + case 'h': + usage(); + exit(0); + default: + printf("?? getopt_long returned character code 0%o ??\n", + getopt_c); + } + } + return; +} + +static void usage(void) +{ + fprintf(stdout, +"fwknop; Single Packet Authorization client\n" +"\n" +"Usage: fwknop -A [-s|-R|-a] -D [options]\n" +"\n" +"Options:\n" +" -A, --Access - Provide a list of ports/protocols to open\n" +" on the server. The format is\n" + ); + return; +} + /***EOF***/ diff --git a/src/fwknop.h b/src/fwknop.h new file mode 100644 index 00000000..bb9bed35 --- /dev/null +++ b/src/fwknop.h @@ -0,0 +1,50 @@ +/* + ***************************************************************************** + * + * File: fwknop.h + * + * Author: Michael Rash (mbr@cipherdyne.org) + * + * Purpose: Header file for fwknop client test program. + * + * Copyright (C) 2009 Michael Rash (mbr@cipherdyne.org) + * + * License (GNU Public License): + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + ***************************************************************************** + * + * $Id$ + * +*/ + +#ifndef __FWKNOP_H__ +#define __FWKNOP_H__ + +/* includes */ +#include +#include +#include +#include +#include "fko.h" + +/* defines */ +#define FWKNOP_VERSION "2.0.0-pre1" + +/* for command argument processing */ +typedef struct { + unsigned char src_addr; /* -s */ + int quiet; + int verbose; +} cmdl_opts; + +#endif /* __FWKNOP_H__ */