diff options
author | Thomas Habets <habets@google.com> | 2014-12-05 10:01:59 +0000 |
---|---|---|
committer | Thomas Habets <habets@google.com> | 2014-12-05 11:03:49 +0000 |
commit | 48d1af17603d50d6073fa19f251cb3e4f853888a (patch) | |
tree | 4b2f327371c375a3b8f963b6bd86153543c7e1ff | |
parent | 639719248c2b5d3a6c376631b3435eb820be89ef (diff) | |
download | arping-48d1af17603d50d6073fa19f251cb3e4f853888a.tar.gz |
Add option -m to allow setting timestamp type.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/arping.8 | 3 | ||||
-rw-r--r-- | doc/arping.yodl | 2 | ||||
-rw-r--r-- | src/arping.c | 53 |
4 files changed, 55 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index a6b7b02..07e67f9 100644 --- a/configure.ac +++ b/configure.ac @@ -65,7 +65,7 @@ AC_FUNC_SELECT_ARGTYPES AC_FUNC_SETVBUF_REVERSED AC_TYPE_SIGNAL AC_CHECK_FUNCS([gettimeofday memset select strchr strdup strerror strstr \ -getifaddrs cap_init pcap_create pcap_set_immediate_mode]) +getifaddrs cap_init pcap_create pcap_list_tstamp_types pcap_set_immediate_mode]) if test x$ac_cv_func_getifaddrs = xyes; then AC_LIBOBJ([findif_getifaddrs]) diff --git a/doc/arping.8 b/doc/arping.8 index c0ba019..0df26af 100644 --- a/doc/arping.8 +++ b/doc/arping.8 @@ -76,6 +76,9 @@ switch is not given, \-i disables this smartness\&. Displays a help message and exits\&. .IP "\-i \fIinterface\fP" Don\(cq\&t guess, use the specified interface\&. +.IP "\-m \fItype\fP" +Type of timestamp to use for incoming packets\&. +Use \-vv when pinging to list available ones\&. .IP "\-p" Turn on promiscious mode on interface, use this if you don\(cq\&t \(dq\&own\(dq\& the MAC address you are using\&. diff --git a/doc/arping.yodl b/doc/arping.yodl index f570afa..cc383e7 100644 --- a/doc/arping.yodl +++ b/doc/arping.yodl @@ -61,6 +61,8 @@ for a host. switch is not given, -i disables this smartness. dit(-h) Displays a help message and exits. dit(-i em(interface)) Don't guess, use the specified interface. + dit(-m em(type)) Type of timestamp to use for incoming packets. + Use -vv when pinging to list available ones. dit(-p) Turn on promiscious mode on interface, use this if you don't "own" the MAC address you are using. dit(-P) Send ARP replies instead of requests. Useful with -U. diff --git a/src/arping.c b/src/arping.c index 937fef7..b6c8e7b 100644 --- a/src/arping.c +++ b/src/arping.c @@ -169,6 +169,7 @@ static unsigned int numsent = 0; /* packets sent */ static unsigned int numrecvd = 0; /* packets received */ static unsigned int max_replies = UINT_MAX; /* exit after -C replies */ static unsigned int numdots = 0; /* dots that should be printed */ +static const char* timestamp_type = NULL; /* Incoming packet measurement ts type (-m) */ static double stats_min_time = -1; static double stats_max_time = -1; @@ -359,12 +360,47 @@ try_pcap_open_live(const char *device, int snaplen, } } #endif - - // FIXME: pcap_set_tstamp_type +#ifdef HAVE_PCAP_LIST_TSTAMP_TYPES + if (timestamp_type) { + int err; + int v = pcap_tstamp_type_name_to_val(timestamp_type); + if (v == PCAP_ERROR) { + fprintf(stderr, "arping: Unknown timestamp type \"%s\"\n", timestamp_type); + exit(1); + } + if ((err = pcap_set_tstamp_type(pcap, v))) { + fprintf(stderr, + "arping: Failed to set timestamp type \"%s\" (%d): %s\n", + timestamp_type, v, pcap_statustostr(err)); + } + } +#endif if ((rc = pcap_activate(pcap))) { snprintf(errbuf, PCAP_ERRBUF_SIZE, "pcap_activate(): %s", pcap_statustostr(rc)); goto err; } +#ifdef HAVE_PCAP_LIST_TSTAMP_TYPES + // List timestamp types after activating, since we don't want to list + // them if activating failed. + if (verbose > 1) { + int *ts; + int count; + count = pcap_list_tstamp_types(pcap, &ts); + if (count == PCAP_ERROR) { + fprintf(stderr, "arping: pcap_list_tstamp_types() failed\n"); + } else { + int c; + const char* fmt = " %-18s %s\n"; + fprintf(stderr, "Timestamp types:\n"); + fprintf(stderr, fmt, "Name", "Description"); + for (c = 0; c < count; c++) { + fprintf(stderr, fmt, pcap_tstamp_type_val_to_name(ts[c]), + pcap_tstamp_type_val_to_description(ts[c])); + } + pcap_free_tstamp_types(ts); + } + } +#endif return pcap; err: if (pcap) { @@ -548,6 +584,12 @@ extended_usage() " -h Displays a help message and exits.\n" " -i interface\n" " Use the specified interface.\n" + " -m type" +#ifndef HAVE_PCAP_LIST_TSTAMP_TYPES + " (Disabled on this system. Option ignored)" +#endif + "\n Type of timestamp to use for incoming packets. Use -vv when\n" + " pinging to list available ones.\n" " -q Does not display messages, except error messages.\n" " -r Raw output: only the MAC/IP address is displayed for each reply.\n" " -R Raw output: Like -r but shows \"the other one\", can be combined\n" @@ -594,7 +636,7 @@ standard_usage() "[ -T <host/ip ] " "[ -s <MAC> ] [ -t <MAC> ] [ -c <count> ]\n" " " - "[ -C <count> ] [ -i <interface> ] " + "[ -C <count> ] [ -i <interface> ] [ -m <type> ] " "<host/ip/MAC | -B>\n"); } @@ -1270,7 +1312,7 @@ int main(int argc, char **argv) memcpy(dstmac, ethxmas, ETH_ALEN); while (EOF != (c = getopt(argc, argv, - "0aAbBC:c:dDeFhi:I:pPqrRs:S:t:T:uUvw:W:"))) { + "0aAbBC:c:dDeFhi:I:m:pPqrRs:S:t:T:uUvw:W:"))) { switch(c) { case '0': srcip = 0; @@ -1323,6 +1365,9 @@ int main(int argc, char **argv) case 'I': /* FALL THROUGH */ ifname = optarg; break; + case 'm': + timestamp_type = optarg; + break; case 'p': promisc = 1; break; |