From b72256a8fcd3fff1209310ee5a02951dd837fc7d Mon Sep 17 00:00:00 2001 From: Anthony DeRobertis Date: Wed, 17 Dec 2014 13:50:53 -0500 Subject: [PATCH 1/2] Add a mode to use random bytes instead of NULLs. This helps defeat data compression on links. --- doc/fping.pod | 5 +++++ src/fping.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/fping.pod b/doc/fping.pod index a21e2ed..f1e8d55 100644 --- a/doc/fping.pod +++ b/doc/fping.pod @@ -151,6 +151,11 @@ Like B<-q>, but show summary results every n seconds. Retry limit (default 3). This is the number of times an attempt at pinging a target will be made, not including the first try. +=item B<-R> + +Instead of using all-zeros as the packet data, generate random bytes. +Use to defeat, e.g., link data compression. + =item B<-s> Print cumulative statistics upon exit. diff --git a/src/fping.c b/src/fping.c index 977a8ac..c9cabdc 100644 --- a/src/fping.c +++ b/src/fping.c @@ -300,6 +300,7 @@ int elapsed_flag, version_flag, count_flag, loop_flag; int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag; int multif_flag; int timestamp_flag = 0; +int random_data_flag = 0; #if defined( DEBUG ) || defined( _DEBUG ) int randomly_lose_flag, sent_times_flag, trace_flag, print_per_system_flag; int lose_factor; @@ -381,7 +382,7 @@ int main( int argc, char **argv ) /* get command line options */ - while( ( c = getopt( argc, argv, "gedhlmnqusaAvDz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:" ) ) != EOF ) + while( ( c = getopt( argc, argv, "gedhlmnqusaAvDRz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:" ) ) != EOF ) { switch( c ) { @@ -477,6 +478,10 @@ int main( int argc, char **argv ) timestamp_flag = 1; break; + case 'R': + random_data_flag = 1; + break; + case 'l': loop_flag = 1; backoff_flag = 0; @@ -1404,7 +1409,13 @@ int send_ping( int s, HOST_ENTRY *h ) if( !buffer ) crash_and_burn( "can't malloc ping packet" ); - memset( buffer, 0, ping_pkt_size * sizeof( char ) ); + if (random_data_flag) { + for (n = 0; n < ping_pkt_size; ++n) { + buffer[n] = random() & 0xFF; + } + } else { + memset( buffer, 0, ping_pkt_size * sizeof( char ) ); + } icp = ( FPING_ICMPHDR* )buffer; gettimeofday( &h->last_send_time, &tz ); @@ -2662,6 +2673,7 @@ void usage(int is_error) fprintf(out, " -q quiet (don't show per-target/per-ping results)\n" ); fprintf(out, " -Q n same as -q, but show summary every n seconds\n" ); fprintf(out, " -r n number of retries (default %d)\n", DEFAULT_RETRY ); + fprintf(out, " -R random packet data (to foil link data compression)\n" ); fprintf(out, " -s print final stats\n" ); fprintf(out, " -S addr set source address\n" ); fprintf(out, " -t n individual target initial timeout (in millisec) (default %d)\n", timeout / 100 ); From 333a16bdbf03a8f094d1e62a2066d9a21763f2f6 Mon Sep 17 00:00:00 2001 From: Anthony DeRobertis Date: Wed, 17 Dec 2014 14:11:40 -0500 Subject: [PATCH 2/2] Fix failing help testcase. The testcase hardcodes the -h (help) output. Seems rather silly, but easy enough to fix. --- ci/test-2-help.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/test-2-help.pl b/ci/test-2-help.pl index fde3e58..c20a4d3 100755 --- a/ci/test-2-help.pl +++ b/ci/test-2-help.pl @@ -34,6 +34,7 @@ ${I_HELP} -l loop sending pings forever -q quiet (don't show per-target/per-ping results) -Q n same as -q, but show summary every n seconds -r n number of retries (default 3) + -R random packet data (to foil link data compression) -s print final stats -S addr set source address -t n individual target initial timeout (in millisec) (default 500)