From: German Service Network Date: Fri, 31 Jul 2026 13:38:53 +0000 (+0200) Subject: Change --print-srcaddr to --print-reply-dst X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acb65796240f6693a4fd3651ba6c502ef5eb8abe;p=fping.git Change --print-srcaddr to --print-reply-dst --- diff --git a/CHANGELOG.md b/CHANGELOG.md index b087d40..94c421e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ Next ## New features -- New option --print-srcaddr to show used IP source address in output (#461, thanks @gsnw-sebast) +- New option --print-reply-dst to show the destination address of the received reply packet (#461, thanks @gsnw-sebast) - New option --oiface for outgoing interface (#463, thanks @gsnw-sebast) ## Bugfixes and other changes diff --git a/ci/test-11-unpriv.pl b/ci/test-11-unpriv.pl index 5bd13d5..f139778 100755 --- a/ci/test-11-unpriv.pl +++ b/ci/test-11-unpriv.pl @@ -49,9 +49,9 @@ sub test_unprivileged_works { $cmd->stderr_is_eq(""); } { - my $cmd = Test::Command->new(cmd => "$fping_copy --print-srcaddr 127.0.0.1"); + my $cmd = Test::Command->new(cmd => "$fping_copy --print-reply-dst 127.0.0.1"); $cmd->exit_is_num(0); - $cmd->stdout_like(qr{127\.0\.0\.1 is alive \(SRC (?:\d+\.\d+\.\d+\.\d+|unknown)\)\n}); + $cmd->stdout_like(qr{127\.0\.0\.1 is alive \(Reply-DST (?:\d+\.\d+\.\d+\.\d+|unknown)\)\n}); $cmd->stderr_is_eq(""); } { diff --git a/ci/test-16-json-output.pl b/ci/test-16-json-output.pl index f4add6a..5f29f38 100644 --- a/ci/test-16-json-output.pl +++ b/ci/test-16-json-output.pl @@ -99,9 +99,9 @@ $cmd->stderr_is_eq(""); } # fping -J -c 1 --print-srcaddr 127.0.0.1 -my $cmd = Test::Command->new(cmd => "fping -J -c 1 --print-srcaddr 127.0.0.1"); +my $cmd = Test::Command->new(cmd => "fping -J -c 1 --print-reply-dst 127.0.0.1"); $cmd->exit_is_num(0); -$cmd->stdout_like(qr/^\{"resp":\s\{"host":\s"127\.0\.0\.1",\s"seq":\s0,\s"size":\s\d+,\s"rtt":\s\d+\.\d+,\s"src":\s"\d+\.\d+\.\d+\.\d+"\}\} +$cmd->stdout_like(qr/^\{"resp":\s\{"host":\s"127\.0\.0\.1",\s"seq":\s0,\s"size":\s\d+,\s"rtt":\s\d+\.\d+,\s"replyDst":\s"\d+\.\d+\.\d+\.\d+"\}\} \{"summary":\s\{"host":\s"127\.0\.0\.1",\s"xmt":\s\d+,\s"rcv":\s\d+,\s"loss":\s\d+,\s"rttMin":\s\d+\.\d+,\s"rttAvg":\s\d+\.\d+,\s"rttMax":\s\d+\.\d+\}\}\n?$/); $cmd->stderr_is_eq(""); diff --git a/doc/fping-json.md b/doc/fping-json.md index 6f1acd8..3dadb84 100644 --- a/doc/fping-json.md +++ b/doc/fping-json.md @@ -82,7 +82,7 @@ Generated when a ping reply is received. contains `originate`, `receive`, `transmit`, and `localreceive` timestamps. - `tos`: If `--print-tos` is used, contains the Type of Service value. - `ttl`: If `--print-ttl` is used, contains the Time To Live value. -- `src`: If `--print-src` is used, contains the source IP address of the responding host. +- `replyDst`: If `--print-reply-dst` is used, contains the destination address of the received reply packet. ### `timeout`: Timeout diff --git a/doc/fping.pod b/doc/fping.pod index 5b2a07f..2b3f075 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -259,11 +259,12 @@ Print cumulative statistics upon exit. Set source address. -=item B<--print-srcaddr> +=item B<--print-reply-dst> -Displays the used IP source address in the output. If B cannot read the source address, -"(SRC unknown)" is returned. -IPv6 is currently not supported. +Displays the destination address of the received reply packet. (IPv6 is currently not supported). +Note this reflects the address as seen on the reply packet, not necessarily the +address the request was sent from. It is only printed for hosts that reply (not for timeouts), +and NAT between fping and the target can make it differ from the request's source or the reply's real origin. =item B<--seqmap-timeout>=I diff --git a/src/flags.c b/src/flags.c index bf2e9ac..60bf484 100644 --- a/src/flags.c +++ b/src/flags.c @@ -32,7 +32,7 @@ int opt_print_netdata_on = 0; int opt_print_json_on = 0; int opt_print_tos_on = 0; int opt_print_ttl_on = 0; -int opt_print_srcaddr_on = 0; +int opt_print_reply_dst_on = 0; int opt_per_recv_on = 0; int opt_report_all_rtts_on = 0; int opt_name_on = 0; diff --git a/src/flags.h b/src/flags.h index 84ff8bd..bcf332a 100644 --- a/src/flags.h +++ b/src/flags.h @@ -36,7 +36,7 @@ extern int opt_print_netdata_on; extern int opt_print_json_on; extern int opt_print_tos_on; extern int opt_print_ttl_on; -extern int opt_print_srcaddr_on; +extern int opt_print_reply_dst_on; extern int opt_per_recv_on; extern int opt_report_all_rtts_on; extern int opt_name_on; diff --git a/src/fping.c b/src/fping.c index 4ada8fd..ba58e77 100644 --- a/src/fping.c +++ b/src/fping.c @@ -270,7 +270,7 @@ IP_HEADER_RESULT default_ip_header_result() { res.otime_ms = 0x80000000U; res.rtime_ms = 0x80000000U; res.ttime_ms = 0x80000000U; - res.src_addr[0] = '\0'; + res.reply_dst_addr[0] = '\0'; return res; } @@ -541,7 +541,7 @@ int main(int argc, char **argv) { "check-source", 0, OPTPARSE_NONE }, { "print-tos", 0, OPTPARSE_NONE }, { "print-ttl", 0, OPTPARSE_NONE }, - { "print-srcaddr", 0, OPTPARSE_NONE }, + { "print-reply-dst", 0, OPTPARSE_NONE }, { "seqmap-timeout", 0, OPTPARSE_REQUIRED }, #if defined(DEBUG) || defined(_DEBUG) { NULL, 'z', OPTPARSE_REQUIRED }, @@ -605,8 +605,8 @@ int main(int argc, char **argv) } } #endif - } else if (strstr(optparse_state.optlongname, "print-srcaddr") != NULL) { - opt_print_srcaddr_on = 1; + } else if (strstr(optparse_state.optlongname, "print-reply-dst") != NULL) { + opt_print_reply_dst_on = 1; } else if (strstr(optparse_state.optlongname, "seqmap-timeout") != NULL) { opt_seqmap_timeout = strtod_strict(optparse_state.optarg) * 1000000; } else if (strstr(optparse_state.optlongname, "oiface") != NULL) { @@ -2366,10 +2366,10 @@ int decode_icmp_ipv4( ip_header_res->ttime_ms = ntohl(icp->icmp_dun.id_ts.its_ttime); } - if (opt_print_srcaddr_on) { - if (ip == NULL || inet_ntop(AF_INET, &ip->ip_dst, ip_header_res->src_addr, sizeof(ip_header_res->src_addr)) == NULL) { - strncpy(ip_header_res->src_addr, "unknown", sizeof(ip_header_res->src_addr) - 1); - ip_header_res->src_addr[sizeof(ip_header_res->src_addr) - 1] = '\0'; + if (opt_print_reply_dst_on) { + if (ip == NULL || inet_ntop(AF_INET, &ip->ip_dst, ip_header_res->reply_dst_addr, sizeof(ip_header_res->reply_dst_addr)) == NULL) { + strncpy(ip_header_res->reply_dst_addr, "unknown", sizeof(ip_header_res->reply_dst_addr) - 1); + ip_header_res->reply_dst_addr[sizeof(ip_header_res->reply_dst_addr) - 1] = '\0'; } } @@ -2493,9 +2493,9 @@ int decode_icmp_ipv6( *id = icp->icmp6_id; *seq = ntohs(icp->icmp6_seq); - if (opt_print_srcaddr_on) { - strncpy(ip_header_res->src_addr, "not supported", sizeof(ip_header_res->src_addr) - 1); - ip_header_res->src_addr[sizeof(ip_header_res->src_addr) - 1] = '\0'; + if (opt_print_reply_dst_on) { + strncpy(ip_header_res->reply_dst_addr, "not supported", sizeof(ip_header_res->reply_dst_addr) - 1); + ip_header_res->reply_dst_addr[sizeof(ip_header_res->reply_dst_addr) - 1] = '\0'; } return 1; @@ -3165,6 +3165,6 @@ void usage(int is_error) fprintf(out, " -X, --fast-reachable=N exits true immediately when N hosts are found\n"); fprintf(out, " --print-tos show received TOS value\n"); fprintf(out, " --print-ttl show IP TTL value\n"); - fprintf(out, " --print-srcaddr show used IP source address (IPv6 is currently not supported).\n"); + fprintf(out, " --print-reply-dst show the destination address of the received reply packet (IPv6 is currently not supported).\n"); exit(is_error); } diff --git a/src/fping.h b/src/fping.h index ef2ca79..f80f25e 100644 --- a/src/fping.h +++ b/src/fping.h @@ -18,7 +18,7 @@ typedef struct ip_header_result { uint32_t otime_ms; uint32_t rtime_ms; uint32_t ttime_ms; - char src_addr[INET6_ADDRSTRLEN]; + char reply_dst_addr[INET6_ADDRSTRLEN]; } IP_HEADER_RESULT; typedef struct host_entry { diff --git a/src/output.c b/src/output.c index 2ce3047..777da4c 100644 --- a/src/output.c +++ b/src/output.c @@ -233,8 +233,8 @@ void print_recv_ext(IP_HEADER_RESULT *ip_header_res, int64_t recv_time, int64_t ms_since_midnight_utc(recv_time)); } - if (ip_header_res->src_addr[0]) { - printf(" (SRC %s)", ip_header_res->src_addr); + if (ip_header_res->reply_dst_addr[0]) { + printf(" (Reply-DST %s)", ip_header_res->reply_dst_addr); } #if defined(HAVE_IP_RECVTOS) @@ -285,8 +285,8 @@ void print_recv_ext_json(IP_HEADER_RESULT *ip_header_res, int64_t recv_time, int printf("\"localreceive\": %u}", ms_since_midnight_utc(recv_time)); } - if (ip_header_res->src_addr[0]) { - printf(", \"src\": \"%s\"", ip_header_res->src_addr); + if (ip_header_res->reply_dst_addr[0]) { + printf(", \"replyDst\": \"%s\"", ip_header_res->reply_dst_addr); } #if defined(HAVE_IP_RECVTOS)