  | 
  
    Flowgrind
    
   Advanced TCP traffic generator 
   | 
 
 
 
 
Go to the documentation of this file.
   51                 buf = realloc(buf, min_size);
 
   53                 buf = malloc(min_size);
 
   67                              bool long_opt, 
const char *
const argument)
 
   69         const int len = strlen(argument);
 
  106         const int len = strlen(msg);
 
  110         ap->
error = (
char *)tmp;
 
  124         for (
int i = 0; i < ap->
data_size; ++i) {
 
  154                               const char *
const opt, 
const char *
const arg,
 
  160         char exact = 0, ambig = 0;
 
  162         for (len = 0; opt[len + 2] && opt[len + 2] != 
'='; ++len) ;
 
  165         for (
int i = 0; options[i].
code != 0; ++i)
 
  167                     && strncmp(options[i].name, &opt[2], len) == 0) {
 
  169                         if (strlen(options[i].name) == len) {
 
  174                         } 
else if (index < 0) {
 
  177                         } 
else if (options[index].code != options[i].code ||
 
  178                                  options[index].has_arg != options[i].has_arg) {
 
  183         if (ambig && !exact) {
 
  202                 if (options[index].has_arg == 
ap_no) {
 
  205                         add_error(ap, 
"' doesn't allow an argument");
 
  208                 if (options[index].has_arg == 
ap_yes && !opt[len + 3]) {
 
  217         if (options[index].has_arg == 
ap_yes) {
 
  218                 if (!arg || !arg[0]) {
 
  243                                const char *
const opt, 
const char *
const arg,
 
  251                 const unsigned char code = opt[cind];
 
  257                         for (
int i = 0; options[i].
code; ++i)
 
  258                                 if (code == options[i].code) {
 
  270                 if (opt[++cind] == 0) {
 
  275                 if (options[index].has_arg != 
ap_no && cind > 0 && opt[cind]) {
 
  280                 } 
else if (options[index].has_arg == 
ap_yes) {
 
  281                         if (!arg || !arg[0]) {
 
  282                                 add_error(ap, 
"option requires an argument -- ");
 
  309         for (i=0; options[i].
code; i++){}
 
  325         for (
int i=0; options[i].
code; i++)
 
  357                 if (options[i].
mutex) {
 
  360                         for (num = 0; options[i].
mutex[num]; num++);
 
  367                         for (
int e=0; e<=num; e++)
 
  375              const int argc, 
const char *
const argv[],
 
  376              const struct ap_Option options[], 
const char in_order)
 
  378         const char **non_options = 0;   
 
  379         int non_options_size = 0;       
 
  391         if (argc < 2 || !argv || !options)
 
  394         while (argind < argc) {
 
  395                 const unsigned char ch1 = argv[argind][0];
 
  396                 const unsigned char ch2 = (ch1 ? argv[argind][1] : 0);
 
  398                 if (ch1 == 
'-' && ch2) {        
 
  399                         const char *
const opt = argv[argind];
 
  400                         const char *
const arg =
 
  401                             (argind + 1 < argc) ? argv[argind + 1] : 0;
 
  403                                 if (!argv[argind][2]) {
 
  408                                         (ap, opt, arg, options, &argind))
 
  413                                 (ap, opt, arg, options, &argind))
 
  421                                                              sizeof *non_options);
 
  424                                 non_options = (
const char **)tmp;
 
  425                                 non_options[non_options_size++] = argv[argind++];
 
  435                 for (
int i = 0; i < non_options_size; ++i)
 
  438                 while (argind < argc)
 
  529                     const int i, 
int *conflict)
 
  
 
static int get_num_options(const struct ap_Option options[])
Determines number of options in options.
 
#define ASSIGN_MAX(s, c)
Assign value if it's greater than current one.
 
static int get_mutex_count(const struct ap_Option options[])
Get the number of mutex in the option definitions.
 
int error_size
Real size of the error string.
 
const struct ap_Option * ap_option(const struct arg_parser *const ap, const int i)
Get the user-defined option for a given record position.
 
int ap_code(const struct arg_parser *const ap, const int i)
Returns the code of a parsed option with given index.
 
const char * ap_argument(const struct arg_parser *const ap, const int i)
Returns the argument of a parsed option.
 
const char * ap_error(const struct arg_parser *const ap)
Get the string containing errors encountered during parsing.
 
int * seen_records
A table containing for each mutex the last seen option record.
 
Internal state of the argument parser.
 
@ ap_no
Option without argument (flag).
 
int * mutex
Null-terminated array of mutex IDs (greater zero) this option belongs to.
 
void ap_reset_mutex(struct ap_Mutex_state *const ms)
Reset a mutex context.
 
int num_mutex
The number of defined mutex.
 
static bool parse_long_option(struct arg_parser *const ap, const char *const opt, const char *const arg, const struct ap_Option options[], int *const argindp)
Parses a long option and adds it to the record of arg-parser ap.
 
struct ap_Record * data
Container for parsed cmdline options.
 
@ ap_yes
Argument required.
 
bool ap_check_mutex(const struct arg_parser *const ap, const struct ap_Mutex_state *const ms, const int i, int *conflict)
Check a new option record for mutex.
 
Contains the state of all mutex.
 
static bool copy_options(struct arg_parser *const ap, const struct ap_Option options[])
Copy options into the arg-parser ap.
 
int code
Short option letter or code (code != 0).
 
bool ap_is_used(const struct arg_parser *const ap, int code)
Returns true if the option specified by code was given at least once.
 
int data_size
Number of parsed records.
 
static void free_data(struct arg_parser *const ap)
Free all space required by the arg-parser ap.
 
bool ap_set_check_mutex(const struct arg_parser *const ap, struct ap_Mutex_state *const ms, const int i, int *conflict)
Check a new option record for mutex and register it at the same time.
 
static bool add_error(struct arg_parser *const ap, const char *const msg)
Add an error message to the arg-parser ap.
 
static bool push_back_record(struct arg_parser *const ap, const int option_index, bool long_opt, const char *const argument)
Store a parsed option in the state of the arg-parser given by ap.
 
void ap_free(struct arg_parser *const ap)
Free internal state of arg-parser.
 
int num_options
Number of known options.
 
static void * ap_resize_buffer(void *buf, const int min_size)
Assure at least a minimum size for buffer buf.
 
int ap_arguments(const struct arg_parser *const ap)
Number of arguments parsed (may be different from argc).
 
char * argument
Argument string (may be empty).
 
Command line argument parser.
 
void ap_free_mutex_state(struct ap_Mutex_state *const ms)
Free a mutex context.
 
Defines a valid command line option.
 
Common definitions used by the Flowgrind daemon, controller, and libs.
 
char * error
Contains errors encountered during parsing.
 
char * name
Long option name (maybe null).
 
static bool parse_short_option(struct arg_parser *const ap, const char *const opt, const char *const arg, const struct ap_Option options[], int *const argindp)
Parses a short option and adds it to the record of arg-parser ap.
 
const char * ap_opt_string(const struct arg_parser *const ap, const int i)
Get the real command line option string (may be the short or long version).
 
bool ap_init_mutex_state(const struct arg_parser *const ap, struct ap_Mutex_state *const ms)
Initialize a new mutex state table.
 
int option_index
Index of the option for internal use (e.g.
 
int num_mutex
The number of defined mutex.
 
bool ap_init(struct arg_parser *const ap, const int argc, const char *const argv[], const struct ap_Option options[], const char in_order)
Initialize the arg-parser given command line and user-defined options.
 
struct ap_Option * options
Array containing user-defined options.
 
bool ap_set_mutex(const struct arg_parser *const ap, struct ap_Mutex_state *const ms, const int i)
Register an option record in a mutex context.
 
char * opt_string
Observed opt string (maybe the long or the short version).
 
Holds a parsed command line option and its argument.