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
This commit is contained in:
Michael Rash 2009-01-26 02:04:25 +00:00
parent 18c0560475
commit 54e1f22a80
2 changed files with 128 additions and 12 deletions

View File

@ -23,12 +23,14 @@
*
*****************************************************************************
*/
#include <stdio.h>
#include <string.h>
#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 <port list> [-s|-R|-a] -D <spa_server> [options]\n"
"\n"
"Options:\n"
" -A, --Access <port list> - Provide a list of ports/protocols to open\n"
" on the server. The format is\n"
);
return;
}
/***EOF***/

50
src/fwknop.h Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#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__ */