add nonzero flag instead of random data for accessing it

develop^2
Eduard Vlad 5 months ago
parent 90ad83fbd0
commit 11a48b4de1

@ -357,7 +357,7 @@ int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag, rdn
int multif_flag, timeout_flag, fast_reachable; int multif_flag, timeout_flag, fast_reachable;
int outage_flag = 0; int outage_flag = 0;
int timestamp_flag = 0; int timestamp_flag = 0;
int random_data_flag = 0; int nonzero_payload_flag = 0;
int cumulative_stats_flag = 0; int cumulative_stats_flag = 0;
#if defined(DEBUG) || defined(_DEBUG) #if defined(DEBUG) || defined(_DEBUG)
int randomly_lose_flag, trace_flag, print_per_system_flag; int randomly_lose_flag, trace_flag, print_per_system_flag;
@ -543,7 +543,7 @@ int main(int argc, char **argv)
{ "quiet", 'q', OPTPARSE_NONE }, { "quiet", 'q', OPTPARSE_NONE },
{ "squiet", 'Q', OPTPARSE_REQUIRED }, { "squiet", 'Q', OPTPARSE_REQUIRED },
{ "retry", 'r', OPTPARSE_REQUIRED }, { "retry", 'r', OPTPARSE_REQUIRED },
{ "random", 'R', OPTPARSE_NONE }, { "nonzero", 'Z', OPTPARSE_NONE },
{ "stats", 's', OPTPARSE_NONE }, { "stats", 's', OPTPARSE_NONE },
{ "src", 'S', OPTPARSE_REQUIRED }, { "src", 'S', OPTPARSE_REQUIRED },
{ "timeout", 't', OPTPARSE_REQUIRED }, { "timeout", 't', OPTPARSE_REQUIRED },
@ -734,8 +734,8 @@ int main(int argc, char **argv)
timestamp_flag = 1; timestamp_flag = 1;
break; break;
case 'R': case 'Z':
random_data_flag = 1; nonzero_payload_flag = 1;
break; break;
case 'l': case 'l':
@ -2981,7 +2981,7 @@ void usage(int is_error)
fprintf(out, " -p, --period=MSEC interval between ping packets to one target (in ms)\n"); fprintf(out, " -p, --period=MSEC interval between ping packets to one target (in ms)\n");
fprintf(out, " (in loop and count modes, default: %.0f ms)\n", perhost_interval / 1e6); fprintf(out, " (in loop and count modes, default: %.0f ms)\n", perhost_interval / 1e6);
fprintf(out, " -r, --retry=N number of retries (default: %d)\n", DEFAULT_RETRY); fprintf(out, " -r, --retry=N number of retries (default: %d)\n", DEFAULT_RETRY);
fprintf(out, " -R, --random random packet data (to foil link data compression)\n"); fprintf(out, " -Z, --nonzero non-zero packet data (same payload as ping 0xA ...)\n");
fprintf(out, " -S, --src=IP set source address\n"); fprintf(out, " -S, --src=IP set source address\n");
fprintf(out, " -t, --timeout=MSEC individual target initial timeout (default: %.0f ms,\n", timeout / 1e6); fprintf(out, " -t, --timeout=MSEC individual target initial timeout (default: %.0f ms,\n", timeout / 1e6);
fprintf(out, " except with -l/-c/-C, where it's the -p period up to 2000 ms)\n"); fprintf(out, " except with -l/-c/-C, where it's the -p period up to 2000 ms)\n");

@ -22,7 +22,7 @@ extern int trace_flag;
void crash_and_burn( char *message ); void crash_and_burn( char *message );
void errno_crash_and_burn( char *message ); void errno_crash_and_burn( char *message );
int in_cksum( unsigned short *p, int n ); int in_cksum( unsigned short *p, int n );
extern int random_data_flag; extern int nonzero_payload_flag;
/* socket.c */ /* socket.c */
int open_ping_socket_ipv4(int *socktype); int open_ping_socket_ipv4(int *socktype);

@ -133,6 +133,7 @@ int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len,
{ {
struct icmp* icp; struct icmp* icp;
int n; int n;
size_t i;
icp = (struct icmp*)ping_buffer_ipv4; icp = (struct icmp*)ping_buffer_ipv4;
@ -142,9 +143,12 @@ int socket_sendto_ping_ipv4(int s, struct sockaddr* saddr, socklen_t saddr_len,
icp->icmp_seq = htons(icmp_seq_nr); icp->icmp_seq = htons(icmp_seq_nr);
icp->icmp_id = icmp_id_nr; icp->icmp_id = icmp_id_nr;
if (random_data_flag) { if (nonzero_payload_flag) {
for (n = ((char*)&icp->icmp_data - (char*)icp); n < ping_pkt_size_ipv4; ++n) { // for (n = ((char*)&icp->icmp_data - (char*)icp); n < ping_pkt_size_ipv4; ++n) {
ping_buffer_ipv4[n] = random() & 0xFF; // ping_buffer_ipv4[n] = random() & 0xFF;
// }
for(n = (char*) &icp->icmp_data - (char*)icp, i = 0xA; n < ping_pkt_size_ipv4; ++n, i += 1) {
ping_buffer_ipv4[n] = i & 0xFF;
} }
} }

@ -115,6 +115,7 @@ int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len,
{ {
struct icmp6_hdr* icp; struct icmp6_hdr* icp;
int n; int n;
size_t i;
icp = (struct icmp6_hdr*)ping_buffer_ipv6; icp = (struct icmp6_hdr*)ping_buffer_ipv6;
icp->icmp6_type = ICMP6_ECHO_REQUEST; icp->icmp6_type = ICMP6_ECHO_REQUEST;
@ -122,9 +123,9 @@ int socket_sendto_ping_ipv6(int s, struct sockaddr* saddr, socklen_t saddr_len,
icp->icmp6_seq = htons(icmp_seq_nr); icp->icmp6_seq = htons(icmp_seq_nr);
icp->icmp6_id = icmp_id_nr; icp->icmp6_id = icmp_id_nr;
if (random_data_flag) { if (nonzero_payload_flag) {
for (n = sizeof(struct icmp6_hdr); n < ping_pkt_size_ipv6; ++n) { for (n = sizeof(struct icmp6_hdr), i = 0xA; n < ping_pkt_size_ipv6; ++n, i+=1) {
ping_buffer_ipv6[n] = random() & 0xFF; ping_buffer_ipv6[n] = i & 0xFF;
} }
} }

Loading…
Cancel
Save