From a715e6a71bfcf3fc2a52cfa444eabbdd116fed5f Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Thu, 9 Jan 2014 11:38:54 +0000 Subject: [PATCH] oping: Add the "-m " command line option. This exposes the new "MARK" functionatlity to command line users. --- src/oping.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/oping.c b/src/oping.c index 28f761c..5442d60 100644 --- a/src/oping.c +++ b/src/oping.c @@ -195,6 +195,7 @@ static double opt_interval = 1.0; static int opt_addrfamily = PING_DEF_AF; static char *opt_srcaddr = NULL; static char *opt_device = NULL; +static char *opt_mark = NULL; static char *opt_filename = NULL; static int opt_count = -1; static int opt_send_ttl = 64; @@ -435,6 +436,7 @@ static void usage_exit (const char *name, int status) /* {{{ */ " Use \"-Q help\" for a list of valid options.\n" " -I srcaddr source address\n" " -D device outgoing interface name\n" + " -m mark mark to set on outgoing packets\n" " -f filename filename to read hosts from\n" #if USE_NCURSES " -u / -U force / disable UTF-8 output\n" @@ -645,7 +647,7 @@ static int read_options (int argc, char **argv) /* {{{ */ while (1) { - optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:P:" + optchar = getopt (argc, argv, "46c:hi:I:t:Q:f:D:Z:P:m:" #if USE_NCURSES "uUg:" #endif @@ -710,6 +712,10 @@ static int read_options (int argc, char **argv) /* {{{ */ opt_device = optarg; break; + case 'm': + opt_mark = optarg; + break; + case 't': { int new_send_ttl; @@ -1736,6 +1742,23 @@ int main (int argc, char **argv) /* {{{ */ } } + if(opt_mark != NULL) + { + char *endp; + int mark = strtoul(opt_mark, &endp, 0); + if(opt_mark[0] != '\0' && *endp == '\0') + { + if(ping_setopt(ping, PING_OPT_MARK, (void*)(&mark)) != 0) + { + fprintf (stderr, "Setting mark failed: %s\n", + ping_get_error (ping)); + } + } + else{ + fprintf(stderr, "Ignoring invalid mark: %s\n", optarg); + } + } + if (opt_filename != NULL) { FILE *infile; -- 2.11.0