#!/usr/bin/perl -w
-use Test::Command tests => 47;
+use Test::Command tests => 53;
use Test::More;
use Time::HiRes qw(gettimeofday tv_interval);
my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp -b 1000 127.0.0.1");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("");
-$cmd->stderr_like(qr{Usage:});
+$cmd->stderr_like(qr{cannot change ICMP Timestamp size});
+}
+
+# fping -b --icmp-timestamp
+{
+my $cmd = Test::Command->new(cmd => "fping -b 1000 --icmp-timestamp 127.0.0.1");
+$cmd->exit_is_num(1);
+$cmd->stdout_is_eq("");
+$cmd->stderr_like(qr{cannot change ICMP Timestamp size});
+}
+
+# fping --icmp-timestamp -b 12 (ICMP Timestamp data size)
+{
+my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp -b 12 127.0.0.1");
+$cmd->exit_is_num(1);
+$cmd->stdout_is_eq("");
+$cmd->stderr_like(qr{cannot change ICMP Timestamp size});
}
# fping -B
20 bytes) and ICMP header (8 bytes), so the minimum total size is 40 bytes.
Default is 56, as in B<ping>. Maximum is the theoretical maximum IP datagram
size (64K), though most systems limit this to a smaller, system-dependent
-number.
+number. Cannot be used together with B<--icmp-timestamp>.
=item B<-B>, B<--backoff>=I<N>
Send ICMP timestamp requests (ICMP type 13) instead of ICMP Echo requests.
Cannot be used together with B<-b> because ICMP timestamp messages have a fixed size.
-IPv4 only, requires root privileges.
+IPv4 only, requires root privileges or cap_net_raw.
=item B<-k>, B<--fwmark>=I<FWMARK>
/* sized so as to be like traditional ping */
#define DEFAULT_PING_DATA_SIZE 56
+/* ICMP Timestamp has a fixed payload size of 12 bytes */
+#define ICMP_TIMESTAMP_DATA_SIZE 12
+
/* maxima and minima */
#ifdef FPING_SAFE_LIMITS
#define MIN_INTERVAL 1 /* in millisec */
int icmp_request_typ = 0;
int print_tos_flag = 0;
int print_ttl_flag = 0;
+int size_flag = 0;
#if defined(DEBUG) || defined(_DEBUG)
int randomly_lose_flag, trace_flag, print_per_system_flag;
int lose_factor;
check_source_flag = 1;
} else if (strstr(optparse_state.optlongname, "icmp-timestamp") != NULL) {
icmp_request_typ = 13;
+ ping_data_size = ICMP_TIMESTAMP_DATA_SIZE;
} else if (strstr(optparse_state.optlongname, "print-tos") != NULL) {
print_tos_flag = 1;
} else if (strstr(optparse_state.optlongname, "print-ttl") != NULL) {
case 'b':
if (sscanf(optparse_state.optarg, "%u", &ping_data_size) != 1)
usage(1);
- if (icmp_request_typ > 0)
- usage(1);
-
+ size_flag = 1;
break;
case 'h':
exit(1);
}
+ if (icmp_request_typ == 13 && size_flag != 0) {
+ fprintf(stderr, "%s: cannot change ICMP Timestamp size\n", prog);
+ exit(1);
+ }
+
if (count_flag) {
if (verbose_flag)
per_recv_flag = 1;
if(icp->icmp_type == ICMP_TSTAMPREPLY) {
/* Check that reply_buf_len is sufficiently big to contain the timestamps */
- if (reply_buf_len < hlen + ICMP_MINLEN + 3 * sizeof(uint32_t)) {
+ if (reply_buf_len < hlen + ICMP_MINLEN + ICMP_TIMESTAMP_DATA_SIZE) {
if (verbose_flag) {
char buf[INET6_ADDRSTRLEN];
getnameinfo(response_addr, response_addr_len, buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);