oping: Add the "-m <mark>" command line option.
[liboping.git] / src / oping.c
index a74cd42..5442d60 100644 (file)
@@ -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"
@@ -444,8 +446,8 @@ static void usage_exit (const char *name, int status) /* {{{ */
                        "  -Z percent   Exit with non-zero exit status if more than this percentage of\n"
                        "               probes timed out. (default: never)\n"
 
-                       "\noping "PACKAGE_VERSION", http://verplant.org/liboping/\n"
-                       "by Florian octo Forster <octo@verplant.org>\n"
+                       "\noping "PACKAGE_VERSION", http://noping.cc/\n"
+                       "by Florian octo Forster <ff@octo.it>\n"
                        "for contributions see `AUTHORS'\n",
                        name);
        exit (status);
@@ -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;
@@ -979,12 +985,19 @@ static int update_graph_prettyping (ping_context_t *ctx, /* {{{ */
        /* Determine the first index in the history we need to draw
         * the graph. */
        history_offset = 0;
-       if (((size_t) x_max) < ctx->history_size)
+       if (((size_t) x_max) < ctx->history_size) /* window is smaller than history */
        {
                if (ctx->history_index > x_max)
                        history_offset = ctx->history_index - x_max;
                else /* wrap around */
-                       history_offset = ctx->history_index + x_max - ctx->history_size;
+                       history_offset = ctx->history_index + ctx->history_size - x_max;
+       }
+       else /* window is larger than history */
+       {
+               if (ctx->history_index != ctx->history_size) /* no longer growing. */
+                       history_offset = ctx->history_index;
+               else /* start-up */
+                       history_offset = 0;
        }
 
        for (x = 0; x < x_max; x++)
@@ -1212,7 +1225,7 @@ static int update_stats_from_context (ping_context_t *ctx, pingobj_iter_t *iter)
                percentile = percentile_to_latency (ctx, opt_percentile);
 
                mvwprintw (ctx->window, /* y = */ 2, /* x = */ 2,
-                               "RTT[ms]: min = %.0f, median = %.0f, p(%.0f) = %.0f, max = %.0f",
+                               "RTT[ms]: min = %.0f, median = %.0f, p(%.0f) = %.0f, max = %.0f  ",
                                min, median, opt_percentile, percentile, max);
        }
 
@@ -1729,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;