📄 parse_cl.c
字号:
/*****************************************************************************
**
** 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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -