diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-03-06 12:37:27 -0800 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2018-03-06 23:31:40 +0000 |
commit | f0fb6ee50c953ac07eb76d47036a761a57f35491 (patch) | |
tree | af767c21f67315c0abbbb9a67bea238e4c121632 /mmdbresolve.c | |
parent | 0ddaec13a162c01928e310c4f92532cdb70d45c0 (diff) |
mmdbresolve: Process our command line arguments by hand.
Visual Studio doesn't ship with a getopt implementation, so process our
arguments ourselves. Note that if we add support for more flags we'll
probably want to use GOption.
Change-Id: Ie78204aa64321ca68f3e66195b8c39e47ca410d9
Reviewed-on: https://code.wireshark.org/review/26288
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'mmdbresolve.c')
-rw-r--r-- | mmdbresolve.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/mmdbresolve.c b/mmdbresolve.c index 3568a0b4b9..8c2959fd66 100644 --- a/mmdbresolve.c +++ b/mmdbresolve.c @@ -14,8 +14,6 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> -#include <unistd.h> - #include <string.h> #include <maxminddb.h> @@ -45,8 +43,9 @@ static const char **lookup_keys[] = { empty_key }; -static void print_usage(void) { +static void exit_err(void) { fprintf(stderr, "Usage: mmdbresolve -f db_file [-f db_file ...]\n"); + exit(1); } int @@ -56,19 +55,22 @@ main(int argc, char *argv[]) size_t mmdb_count = 0; MMDB_s *mmdbs = NULL; int mmdb_err; - int opt; - const char *optstring = "f:"; char *out_buf = (char *) malloc(OUT_BUF_SIZE); setvbuf(stdout, out_buf, _IOFBF, OUT_BUF_SIZE); fprintf(stdout, "[init]\n"); - while ((opt = getopt(argc, argv, optstring)) != -1) { - if (opt == 'f') { + // If we need to handle anything beyond "-f" we'll probably want to + // link with GLib and use GOption. + int arg_idx = 0; + while (arg_idx < argc - 1) { + if (strcmp(argv[arg_idx], "-f") == 0) { + arg_idx++; + const char *db_arg = argv[arg_idx]; MMDB_s try_mmdb; - mmdb_err = MMDB_open(optarg, 0, &try_mmdb); - fprintf(stdout, "db.%zd.path: %s\n", mmdb_count, optarg); + mmdb_err = MMDB_open(db_arg, 0, &try_mmdb); + fprintf(stdout, "db.%zd.path: %s\n", mmdb_count, db_arg); fprintf(stdout, "db.%zd.status: ", mmdb_count); if (mmdb_err == MMDB_SUCCESS) { mmdb_count++; @@ -79,16 +81,16 @@ main(int argc, char *argv[]) } else { fprintf(stdout, "ERROR %s\n", MMDB_strerror(mmdb_err)); } - }; + } + arg_idx++; } fprintf(stdout, "mmdbresolve.status: %s\n", mmdb_count > 0 ? "true": "false"); fprintf(stdout, "# End init\n"); fflush(stdout); - if (mmdb_count < 1) { - print_usage(); - exit(1); + if (arg_idx != argc || mmdb_count < 1) { + exit_err(); } while (!feof(stdin)) { |