#!/usr/bin/perl -w
-use Test::Command tests => 78;
+use Test::Command tests => 84;
use Test::More;
# -c n count of pings to send to each target (default 1)
});
}
+# fping -c n --print-tos --print-ttl
+{
+my $cmd = Test::Command->new(cmd => "fping -4 -c 2 -p 100 --print-tos --print-ttl localhost 127.0.0.1");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+});
+
+$cmd->stderr_like(qr{localhost : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
+127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
+});
+}
+
# fping -c n -q
{
my $cmd = Test::Command->new(cmd => "fping -q -c 2 -p 100 localhost 127.0.0.1");
});
}
+# fping -C n --print-tos --print-ttl
+{
+my $cmd = Test::Command->new(cmd => "fping -4 -C 2 -p 100 --print-tos --print-ttl localhost 127.0.0.1");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr{localhost : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+localhost : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+});
+
+$cmd->stderr_like(qr{localhost : \d\.\d+ \d\.\d+
+127\.0\.0\.1 : \d\.\d+ \d\.\d+
+});
+}
+
# fping -C n -q
{
my $cmd = Test::Command->new(cmd => "fping -C 5 -q -p 100 localhost");
#!/usr/bin/perl -w
-use Test::Command tests => 15;
+use Test::Command tests => 16;
use Test::More;
# -i n interval between sending ping packets (in millisec) (default 25)
});
}
+# fping -l --print-tos --print-ttl
+{
+my $cmd = Test::Command->new(cmd => '(sleep 2; pkill fping)& fping -p 900 --print-ttl --print-tos -l 127.0.0.1');
+$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+127\.0\.0\.1 : \[1\], 64 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\) \(TOS \d+\) \(TTL \d+\)
+});
+}
+
# fping -k
SKIP: {
if($^O ne 'linux') {
if (verbose_flag)
printf(" is alive");
-
- if(print_tos_flag) {
- if(ip_header_tos != -1) {
- printf(" (TOS %d)", ip_header_tos);
- }
- else {
- printf(" (TOS unknown)");
- }
- }
-
- if (print_ttl_flag) {
- if(ip_header_ttl != -1) {
- printf(" (TTL %d)", ip_header_ttl);
- }
- else {
- printf(" (TTL unknown)");
- }
- }
-
- if (icmp_request_typ == 13) {
- printf(" (Timestamp Originate=%u Receive=%u Transmit=%u Localreceive=%u)",
- ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms,
- ms_since_midnight_utc(recv_time));
- }
-
- if (elapsed_flag)
- printf(" (%s ms)", sprint_tm(this_reply));
-
- if (addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
- char buf[INET6_ADDRSTRLEN];
- getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
- fprintf(stderr, " [<- %s]", buf);
- }
-
- printf("\n");
}
}
printf("%d%% return)",
(h->num_recv_total * 100) / h->num_sent);
}
+ }
+
+ if (verbose_flag || alive_flag || per_recv_flag) {
if (addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
char buf[INET6_ADDRSTRLEN];
fprintf(stderr, " [<- %s]", buf);
}
+ if(print_tos_flag) {
+ if(ip_header_tos != -1) {
+ printf(" (TOS %d)", ip_header_tos);
+ }
+ else {
+ printf(" (TOS unknown)");
+ }
+ }
+
+ if (print_ttl_flag) {
+ if(ip_header_ttl != -1) {
+ printf(" (TTL %d)", ip_header_ttl);
+ }
+ else {
+ printf(" (TTL unknown)");
+ }
+ }
+
if (icmp_request_typ == 13) {
- printf(", ICMP timestamp: Originate=%u Receive=%u Transmit=%u Localreceive=%u",
+ printf("%simestamp%s Originate=%u Receive=%u Transmit=%u Localreceive=%u%s",
+ per_recv_flag ? ", ICMP t" : " (T",
+ per_recv_flag ? ":" : "",
ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms,
- ms_since_midnight_utc(recv_time));
+ ms_since_midnight_utc(recv_time),
+ per_recv_flag ? "" : ")");
}
+ if (elapsed_flag && !per_recv_flag)
+ printf(" (%s ms)", sprint_tm(this_reply));
+
printf("\n");
}