diff --git a/src/fping.c b/src/fping.c index c58e20c..1c65cbd 100644 --- a/src/fping.c +++ b/src/fping.c @@ -561,6 +561,16 @@ int main(int argc, char **argv) float opt_value_float; while ((c = optparse_long(&optparse_state, longopts, NULL)) != EOF) { switch (c) { + case '0': + /* + * Use long-option example + * Define "struct optparse_long longopts": { "long-option-name", '0', OPTPARSE_NONE } + * + * if(strstr(optparse_state.optlongname, "long-option-name") != NULL) { + * long_option_flag = 1; + * } + */ + break; case '4': #ifdef IPV6 if (hints_ai_family != AF_UNSPEC && hints_ai_family != AF_INET) { diff --git a/src/optparse.c b/src/optparse.c index 4242bff..63a9f40 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -238,12 +238,14 @@ optparse_long(struct optparse *options, /* Parse as long option. */ options->errmsg[0] = '\0'; options->optopt = 0; + options->optlongname = 0; options->optarg = 0; option += 2; /* skip "--" */ options->optind++; for (int i = 0; !longopts_end(longopts, i); i++) { const char *name = longopts[i].longname; if (longopts_match(name, option)) { + options->optlongname = option; if (longindex) *longindex = i; options->optopt = longopts[i].shortname; diff --git a/src/optparse.h b/src/optparse.h index f124b75..7a555ed 100644 --- a/src/optparse.h +++ b/src/optparse.h @@ -48,6 +48,7 @@ struct optparse { int permute; int optind; int optopt; + char *optlongname; char *optarg; char errmsg[64]; int subopt;