[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] Add --queries option to traceroute
From: |
Debarshi Ray |
Subject: |
[bug-inetutils] Add --queries option to traceroute |
Date: |
Wed, 16 Apr 2008 19:35:17 +0530 |
Here (http://rishi.fedorapeople.org/gnu/traceroute-queries.diff and
below) is a patch to add a new '-q, --queries' option to GNU
traceroute:
diff -urNp inetutils/traceroute/traceroute.c
inetutils-build/traceroute/traceroute.c
--- inetutils/traceroute/traceroute.c 2007-06-29 21:59:28.000000000 +0530
+++ inetutils-build/traceroute/traceroute.c 2008-04-16 18:54:26.000000000
+0530
@@ -47,6 +47,7 @@
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
+#include <error.h>
#include <limits.h>
#include <assert.h>
#include <argp.h>
@@ -58,7 +59,7 @@
#define TIME_INTERVAL 3
void do_try (trace_t * trace, const int hop,
- const int max_hops, const int max_tries);
+ const int max_hops, const long int max_queries);
char *get_hostname (struct in_addr *addr);
@@ -69,7 +70,7 @@ struct sockaddr_in dest;
int opt_port = 33434;
int opt_max_hops = 64;
-int opt_max_tries = 3;
+static long int opt_max_queries = 3;
int opt_resolve_hostnames = 0;
ARGP_PROGRAM_DATA ("traceroute", "2007", "Elian Gidoni");
@@ -86,6 +87,8 @@ static struct argp_option argp_options[]
#define GRP 0
{"port", 'p', "PORT", 0, "Use destination PORT port (default: 33434)",
GRP+1},
+ {"queries", 'q', "NUM", 0, "Send NUM probe packets per hop (default: 3)",
+ GRP+1},
{"resolve-hostnames", OPT_RESOLVE, NULL, 0, "Resolve hostnames", GRP+1},
#undef GRP
{NULL}
@@ -105,6 +108,14 @@ parse_opt (int key, char *arg, struct ar
error (EXIT_FAILURE, 0, "invalid port number `%s'", arg);
break;
+ case 'q':
+ opt_max_queries = strtol (arg, &p, 10);
+ if (*p)
+ argp_error (state, "invalid value (`%s' near `%s')", arg, p);
+ if (opt_max_queries < 1 || opt_max_queries > 10)
+ error (EXIT_FAILURE, 0, "number of queries should be within [1, 10]");
+ break;
+
case OPT_RESOLVE:
opt_resolve_hostnames = 1;
break;
@@ -155,7 +166,7 @@ main (int argc, char **argv)
{
if (hop > opt_max_hops)
exit (0);
- do_try (&trace, hop, opt_max_hops, opt_max_tries);
+ do_try (&trace, hop, opt_max_hops, opt_max_queries);
trace_inc_ttl (&trace);
trace_inc_port (&trace);
hop++;
@@ -166,10 +177,11 @@ main (int argc, char **argv)
void
do_try (trace_t * trace, const int hop,
- const int max_hops, const int max_tries)
+ const int max_hops, const long int max_queries)
{
fd_set readset;
- int ret, tries, readonly = 0;
+ int ret, readonly = 0;
+ long int queries;
struct timeval now, time;
struct hostent *host;
double triptime = 0.0;
@@ -177,7 +189,7 @@ do_try (trace_t * trace, const int hop,
printf (" %d ", hop);
- for (tries = 0; tries < max_tries; tries++)
+ for (queries = 0; queries < max_queries; queries++)
{
FD_ZERO (&readset);
FD_SET (trace_icmp_sock (trace), &readset);
@@ -223,13 +235,13 @@ do_try (trace_t * trace, const int hop,
if (trace_read (trace))
{
/* FIXME: printf ("Some error ocurred\n"); */
- tries--;
+ queries--;
readonly = 1;
continue;
}
else
{
- if (tries == 0 || prev_addr != trace->from.sin_addr.s_addr)
+ if (queries == 0 || prev_addr != trace->from.sin_addr.s_addr)
printf (" %s (%s) ",
inet_ntoa (trace->from.sin_addr),
get_hostname (&trace->from.sin_addr));
This option is provided by all the other flavours of traceroute (most
of them from BSD) that I could find. All of them stress on NUM being
greater than 0, while a few of them also require it to be less than or
equal to 10. I chose [0, 10] as an interval for NUM since 10 looks
like a reasonably big number for the purposes of traceroute.
Here is some initial testing that my friend, Vivek, did for me:
http://pastebin.ca/987352
Comments?
Happy hacking,
Debarshi
--
"From what we get, we can make a living; what we give, however, makes a life."
-- Arthur Ashe
- [bug-inetutils] Add --queries option to traceroute,
Debarshi Ray <=
- Re: [bug-inetutils] Add --queries option to traceroute, Alfred M. Szmidt, 2008/04/16
- Re: [bug-inetutils] Add --queries option to traceroute, Alfred M. Szmidt, 2008/04/16
- Re: [bug-inetutils] Add --queries option to traceroute, Debarshi Ray, 2008/04/16
- Re: [bug-inetutils] Add --queries option to traceroute, Debarshi Ray, 2008/04/16
- Re: [bug-inetutils] Add --queries option to traceroute, Alfred M. Szmidt, 2008/04/17
- Re: [bug-inetutils] Add --queries option to traceroute, Debarshi Ray, 2008/04/17
- Re: [bug-inetutils] Add --queries option to traceroute, Alfred M. Szmidt, 2008/04/17
- Re: [bug-inetutils] Add --queries option to traceroute, Alfred M. Szmidt, 2008/04/17