1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*****************************************************************************
**
** parse_cl.c
**
** Thu Mar 25 07:42:05 1999
** mborella@stratos (Mike Borella)
**
** Main command line parsing routines
**
** Automatically created by genparse v0.2.2
**
** See http://www.xnet.com/~cathmike/MSB/Software/ for details
**
*****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "parse_cl.h"
/*----------------------------------------------------------------------------
*
* usage()
*
*----------------------------------------------------------------------------
*/
void usage(char *exc)
{
printf("usage: %s [ -cibplntm ]\n", exc);
printf(" [ -c ] ");
printf("[ --count ] ");
printf("Exit after receiving 'count' packets");
printf("\n");
printf(" [ -i ] ");
printf("[ --interface ] ");
printf("Listen on interface 'interface'");
printf("\n");
printf(" [ -b ] ");
printf("Make stdout buffered");
printf("\n");
printf(" [ -p ] ");
printf("Dump packet payloads");
printf("\n");
printf(" [ -l ] ");
printf("Don't print link-layer headers");
printf("\n");
printf(" [ -n ] ");
printf("Don't print network-layer headers");
printf("\n");
printf(" [ -t ] ");
printf("Don't print transport-layer headers");
printf("\n");
printf(" [ -m ] ");
printf("Minimal output");
printf("\n");
exit(1);
}
/*----------------------------------------------------------------------------
*
* free_args()
*
*----------------------------------------------------------------------------
*/
void free_args(struct arg_t *my_arg)
{
if (my_arg->i != NULL) free(my_arg->i);
free(my_arg);
}
/*----------------------------------------------------------------------------
*
* parse_cl()
*
*----------------------------------------------------------------------------
*/
struct arg_t *parse_cl(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
int option_index = 0;
char c;
struct arg_t *my_arg;
int errflg = 0;
static struct option long_options[] =
{
{"count", 1, 0, 'c'},
{"interface", 1, 0, 'i'},
{"", 1, 0, 'b'},
{"", 1, 0, 'p'},
{"", 1, 0, 'l'},
{"", 1, 0, 'n'},
{"", 1, 0, 't'},
{"", 1, 0, 'm'},
{0, 0, 0, 0}
};
my_arg = (struct arg_t *) malloc (sizeof(struct arg_t));
my_arg->i = NULL;
my_arg->b = 0;
my_arg->p = 0;
my_arg->l = 0;
my_arg->n = 0;
my_arg->t = 0;
my_arg->m = 0;
while ((c = getopt_long(argc, argv, "c:i:bplntm", long_options, &option_index)) != EOF)
{
switch(c)
{
case 'c':
my_arg->c = atoi(optarg);
if (my_arg->c < 1)
{
fprintf(stderr, "parameter range error: c must be >= 1\n");
errflg ++;
}
break;
case 'i':
my_arg->i = strdup(optarg);
break;
case 'b':
my_arg->b ++;
break;
case 'p':
my_arg->p ++;
break;
case 'l':
my_arg->l ++;
break;
case 'n':
my_arg->n ++;
break;
case 't':
my_arg->t ++;
break;
case 'm':
my_arg->m ++;
break;
default:
usage(argv[0]);
}
} /* while */
if (errflg)
usage(argv[0]);
if (!(my_arg))
usage(argv[0]);
my_arg->optind = optind;
return my_arg;
}
|