#!/usr/bin/perl -w
-use Test::Command tests => 63;
+use Test::Command tests => 66;
use Test::More;
# fping -J -c 2 127.0.0.1
$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");
+$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+"\}\}
+\{"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("");
+
# fping -J -c 1 -q 127.0.0.1
{
my $cmd = Test::Command->new(cmd => "fping -J -c 1 -q 127.0.0.1");
#endif
IP_HEADER_RESULT default_ip_header_result() {
- return (IP_HEADER_RESULT){-1, -1, 0x80000000U, 0x80000000U, 0x80000000U};
+ IP_HEADER_RESULT res;
+ res.tos = -1;
+ res.ttl = -1;
+ res.otime_ms = 0x80000000U;
+ res.rtime_ms = 0x80000000U;
+ res.ttime_ms = 0x80000000U;
+ res.src_addr[0] = '\0';
+ return res;
}
int event_storage_count;
{ "check-source", 0, OPTPARSE_NONE },
{ "print-tos", 0, OPTPARSE_NONE },
{ "print-ttl", 0, OPTPARSE_NONE },
+ { "print-srcaddr", 0, OPTPARSE_NONE },
{ "seqmap-timeout", 0, OPTPARSE_REQUIRED },
#if defined(DEBUG) || defined(_DEBUG)
{ NULL, 'z', OPTPARSE_REQUIRED },
}
}
#endif
+ } else if (strstr(optparse_state.optlongname, "print-srcaddr") != NULL) {
+ opt_print_srcaddr_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) {
{
struct icmp *icp;
int hlen = 0;
+ struct ip *ip = NULL;
if (!using_sock_dgram4) {
- struct ip *ip = (struct ip *)reply_buf;
+ ip = (struct ip *)reply_buf;
ip_header_res->tos = ip->ip_tos;
ip_header_res->ttl = ip->ip_ttl;
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';
+ }
+ }
+
return hlen;
}
char *reply_buf,
size_t reply_buf_len,
unsigned short *id,
- unsigned short *seq)
+ unsigned short *seq,
+ IP_HEADER_RESULT *ip_header_res)
{
struct icmp6_hdr *icp;
*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';
+ }
+
return 1;
}
#endif
buffer,
sizeof(buffer),
&id,
- &seq)) {
+ &seq,
+ &ip_header_res)) {
return 1;
}
if (id != ident6) {
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");
exit(is_error);
}
ms_since_midnight_utc(recv_time));
}
+ if (ip_header_res->src_addr[0]) {
+ printf(" (SRC %s)", ip_header_res->src_addr);
+ }
+
#if defined(HAVE_IP_RECVTOS)
if(opt_print_tos_on) {
if(ip_header_res->tos != -1) {
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 defined(HAVE_IP_RECVTOS)
if(opt_print_tos_on) {
if(ip_header_res->tos != -1) {