remove trailing whitespace, fix mixed whitespace

pull/89/merge
David Schweikert 8 years ago
parent 9d2daa77c8
commit d017390cbc

@ -407,12 +407,12 @@ int main( int argc, char **argv )
usage(1); usage(1);
break; break;
case 'r': case 'r':
if (!sscanf(optarg,"%u",&retry)) if (!sscanf(optarg,"%u",&retry))
usage(1); usage(1);
break; break;
case 'i': case 'i':
if (!sscanf(optarg,"%u",&interval)) if (!sscanf(optarg,"%u",&interval))
usage(1); usage(1);
@ -428,14 +428,14 @@ int main( int argc, char **argv )
case 'c': case 'c':
if( !( count = ( unsigned int )atoi( optarg ) ) ) if( !( count = ( unsigned int )atoi( optarg ) ) )
usage(1); usage(1);
count_flag = 1; count_flag = 1;
break; break;
case 'C': case 'C':
if( !( count = ( unsigned int )atoi( optarg ) ) ) if( !( count = ( unsigned int )atoi( optarg ) ) )
usage(1); usage(1);
count_flag = 1; count_flag = 1;
report_all_rtts_flag = 1; report_all_rtts_flag = 1;
break; break;
@ -443,7 +443,7 @@ int main( int argc, char **argv )
case 'b': case 'b':
if (!sscanf(optarg,"%i",&ping_data_size)) if (!sscanf(optarg,"%i",&ping_data_size))
usage(1); usage(1);
break; break;
case 'h': case 'h':
@ -460,7 +460,7 @@ int main( int argc, char **argv )
quiet_flag = 1; quiet_flag = 1;
if( !( report_interval = ( unsigned int )atoi( optarg ) * 100000 ) ) if( !( report_interval = ( unsigned int )atoi( optarg ) * 100000 ) )
usage(1); usage(1);
break; break;
case 'e': case 'e':
@ -487,7 +487,7 @@ int main( int argc, char **argv )
case 'B': case 'B':
if( !( backoff = atof( optarg ) ) ) if( !( backoff = atof( optarg ) ) )
usage(1); usage(1);
break; break;
case 's': case 's':
@ -524,7 +524,7 @@ int main( int argc, char **argv )
case 'z': case 'z':
if( ! ( debugging = ( unsigned int )atoi( optarg ) ) ) if( ! ( debugging = ( unsigned int )atoi( optarg ) ) )
usage(1); usage(1);
break; break;
#endif /* DEBUG || _DEBUG */ #endif /* DEBUG || _DEBUG */
@ -609,9 +609,9 @@ int main( int argc, char **argv )
{ {
fprintf( stderr, "%s: specify only one of c, l\n", argv[0] ); fprintf( stderr, "%s: specify only one of c, l\n", argv[0] );
exit(1); exit(1);
}/* IF */ }/* IF */
if( ( interval < MIN_INTERVAL * 100 || if( ( interval < MIN_INTERVAL * 100 ||
perhost_interval < MIN_PERHOST_INTERVAL * 100 ) perhost_interval < MIN_PERHOST_INTERVAL * 100 )
&& getuid() ) && getuid() )
@ -621,51 +621,51 @@ int main( int argc, char **argv )
prog, MIN_INTERVAL, MIN_PERHOST_INTERVAL ); prog, MIN_INTERVAL, MIN_PERHOST_INTERVAL );
exit(1); exit(1);
}/* IF */ }/* IF */
if( ping_data_size > MAX_PING_DATA ) if( ping_data_size > MAX_PING_DATA )
{ {
fprintf( stderr, "%s: data size %u not valid, must be lower than %u\n", fprintf( stderr, "%s: data size %u not valid, must be lower than %u\n",
prog, ping_data_size, (unsigned int) MAX_PING_DATA ); prog, ping_data_size, (unsigned int) MAX_PING_DATA );
exit(1); exit(1);
}/* IF */ }/* IF */
if( ( backoff > MAX_BACKOFF_FACTOR ) || ( backoff < MIN_BACKOFF_FACTOR ) ) if( ( backoff > MAX_BACKOFF_FACTOR ) || ( backoff < MIN_BACKOFF_FACTOR ) )
{ {
fprintf( stderr, "%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n", fprintf( stderr, "%s: backoff factor %.1f not valid, must be between %.1f and %.1f\n",
prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR ); prog, backoff, MIN_BACKOFF_FACTOR, MAX_BACKOFF_FACTOR );
exit(1); exit(1);
}/* IF */ }/* IF */
if( alive_flag || unreachable_flag ) if( alive_flag || unreachable_flag )
verbose_flag = 0; verbose_flag = 0;
if( count_flag ) if( count_flag )
{ {
if( verbose_flag ) if( verbose_flag )
per_recv_flag = 1; per_recv_flag = 1;
alive_flag = unreachable_flag = verbose_flag = 0; alive_flag = unreachable_flag = verbose_flag = 0;
}/* IF */ }/* IF */
if( loop_flag ) if( loop_flag )
{ {
if( !report_interval ) if( !report_interval )
per_recv_flag = 1; per_recv_flag = 1;
alive_flag = unreachable_flag = verbose_flag = 0; alive_flag = unreachable_flag = verbose_flag = 0;
}/* IF */ }/* IF */
trials = ( count > retry + 1 ) ? count : retry + 1; trials = ( count > retry + 1 ) ? count : retry + 1;
#if defined( DEBUG ) || defined( _DEBUG ) #if defined( DEBUG ) || defined( _DEBUG )
if( debugging & DBG_TRACE ) if( debugging & DBG_TRACE )
trace_flag = 1; trace_flag = 1;
if( ( debugging & DBG_SENT_TIMES ) && !loop_flag ) if( ( debugging & DBG_SENT_TIMES ) && !loop_flag )
sent_times_flag = 1; sent_times_flag = 1;
@ -673,16 +673,16 @@ int main( int argc, char **argv )
{ {
randomly_lose_flag = 1; randomly_lose_flag = 1;
lose_factor = 1; /* ie, 1/4 */ lose_factor = 1; /* ie, 1/4 */
}/* IF */ }/* IF */
if( debugging & DBG_RANDOM_LOSE_MANY ) if( debugging & DBG_RANDOM_LOSE_MANY )
{ {
randomly_lose_flag = 1; randomly_lose_flag = 1;
lose_factor = 5; /* ie, 3/4 */ lose_factor = 5; /* ie, 3/4 */
}/* IF */ }/* IF */
if( debugging & DBG_PRINT_PER_SYSTEM ) if( debugging & DBG_PRINT_PER_SYSTEM )
print_per_system_flag = 1; print_per_system_flag = 1;
@ -697,7 +697,7 @@ int main( int argc, char **argv )
perhost_interval / 10, timeout / 10 ); perhost_interval / 10, timeout / 10 );
fprintf( stderr, " ping_data_size = %u, trials = %u\n", fprintf( stderr, " ping_data_size = %u, trials = %u\n",
ping_data_size, trials ); ping_data_size, trials );
if( verbose_flag ) fprintf( stderr, " verbose_flag set\n" ); if( verbose_flag ) fprintf( stderr, " verbose_flag set\n" );
if( multif_flag ) fprintf( stderr, " multif_flag set\n" ); if( multif_flag ) fprintf( stderr, " multif_flag set\n" );
if( name_flag ) fprintf( stderr, " name_flag set\n" ); if( name_flag ) fprintf( stderr, " name_flag set\n" );
@ -754,7 +754,7 @@ int main( int argc, char **argv )
/* if no conditions are specified, then assume input from stdin */ /* if no conditions are specified, then assume input from stdin */
if( !*argv && !filename && !generate_flag ) if( !*argv && !filename && !generate_flag )
filename = "-"; filename = "-";
if( *argv && !generate_flag ) if( *argv && !generate_flag )
{ {
while( *argv ) while( *argv )
@ -769,7 +769,7 @@ int main( int argc, char **argv )
FILE *ping_file; FILE *ping_file;
char line[132]; char line[132];
char host[132]; char host[132];
if( strcmp( filename, "-" ) == 0 ) if( strcmp( filename, "-" ) == 0 )
ping_file = fdopen( 0, "r" ); ping_file = fdopen( 0, "r" );
else else
@ -783,31 +783,31 @@ int main( int argc, char **argv )
{ {
if( sscanf( line, "%s", host ) != 1 ) if( sscanf( line, "%s", host ) != 1 )
continue; continue;
if( ( !*host ) || ( host[0] == '#' ) ) /* magic to avoid comments */ if( ( !*host ) || ( host[0] == '#' ) ) /* magic to avoid comments */
continue; continue;
add_name(host); add_name(host);
}/* WHILE */ }/* WHILE */
fclose( ping_file ); fclose( ping_file );
} }
else if( *argv && generate_flag ) { else if( *argv && generate_flag ) {
if(argc == 1) { if(argc == 1) {
/* one target: we expect a cidr range (n.n.n.n/m) */ /* one target: we expect a cidr range (n.n.n.n/m) */
add_cidr(argv[0]); add_cidr(argv[0]);
} }
else if(argc == 2) { else if(argc == 2) {
add_range(argv[0], argv[1]); add_range(argv[0], argv[1]);
} }
else { else {
usage(1); usage(1);
} }
} }
else { else {
usage(1); usage(1);
} }
if(!num_hosts) { if(!num_hosts) {
exit(num_noaddress ? 2 : 1); exit(num_noaddress ? 2 : 1);
} }
@ -828,7 +828,7 @@ int main( int argc, char **argv )
{ {
table[num_jobs] = cursor; table[num_jobs] = cursor;
cursor->i = num_jobs; cursor->i = num_jobs;
/* as long as we're here, put this in so names print out nicely */ /* as long as we're here, put this in so names print out nicely */
if( count_flag || loop_flag ) if( count_flag || loop_flag )
{ {
@ -836,7 +836,7 @@ int main( int argc, char **argv )
buf = ( char* ) malloc( n + 1 ); buf = ( char* ) malloc( n + 1 );
if( !buf ) if( !buf )
crash_and_burn( "can't malloc host pad" ); crash_and_burn( "can't malloc host pad" );
for ( i = 0; i < n; i++ ) for ( i = 0; i < n; i++ )
buf[i] = ' '; buf[i] = ' ';
@ -844,7 +844,7 @@ int main( int argc, char **argv )
cursor->pad = buf; cursor->pad = buf;
}/* IF */ }/* IF */
cursor=cursor->ev_next; cursor=cursor->ev_next;
}/* FOR */ }/* FOR */
@ -852,7 +852,7 @@ int main( int argc, char **argv )
init_ping_buffer(ping_data_size); init_ping_buffer(ping_data_size);
signal( SIGINT, finish ); signal( SIGINT, finish );
gettimeofday( &start_time, &tz ); gettimeofday( &start_time, &tz );
current_time = start_time; current_time = start_time;
@ -1019,7 +1019,7 @@ void main_loop()
h = ev_dequeue(); h = ev_dequeue();
/* Send the ping */ /* Send the ping */
/*printf("Sending ping after %d ms\n", lt/100); */ /*printf("Sending ping after %d ms\n", lt/100); */
send_ping(s, h); send_ping(s, h);
/* Check what needs to be done next */ /* Check what needs to be done next */
@ -1075,24 +1075,24 @@ void main_loop()
/* When can we expect the next event? */ /* When can we expect the next event? */
if(ev_first) { if(ev_first) {
if(ev_first->ev_time.tv_sec == 0) { if(ev_first->ev_time.tv_sec == 0) {
wait_time = 0; wait_time = 0;
} }
else { else {
wait_time = timeval_diff(&ev_first->ev_time, &current_time); wait_time = timeval_diff(&ev_first->ev_time, &current_time);
if(wait_time < 0) wait_time = 0; if(wait_time < 0) wait_time = 0;
} }
if(ev_first->ev_type == EV_TYPE_PING) { if(ev_first->ev_type == EV_TYPE_PING) {
/* make sure that we wait enough, so that the inter-ping delay is /* make sure that we wait enough, so that the inter-ping delay is
* bigger than 'interval' */ * bigger than 'interval' */
if(wait_time < interval) { if(wait_time < interval) {
lt = timeval_diff(&current_time, &last_send_time); lt = timeval_diff(&current_time, &last_send_time);
if(lt < interval) { if(lt < interval) {
wait_time = interval-lt; wait_time = interval-lt;
} }
else { else {
wait_time = 0; wait_time = 0;
} }
} }
} }
#if defined( DEBUG ) || defined( _DEBUG ) #if defined( DEBUG ) || defined( _DEBUG )
@ -1146,7 +1146,7 @@ void main_loop()
Inputs: void (none) Inputs: void (none)
Description: Description:
Main program clean up and exit point Main program clean up and exit point
************************************************************/ ************************************************************/
@ -1173,9 +1173,9 @@ void finish()
if( verbose_flag ) if( verbose_flag )
printf( " is unreachable" ); printf( " is unreachable" );
printf( "\n" ); printf( "\n" );
}/* IF */ }/* IF */
}/* IF */ }/* IF */
}/* FOR */ }/* FOR */
@ -1194,7 +1194,7 @@ void finish()
exit( 2 ); exit( 2 );
else if( num_alive != num_hosts ) else if( num_alive != num_hosts )
exit( 1 ); exit( 1 );
exit(0); exit(0);
} /* finish() */ } /* finish() */
@ -1209,7 +1209,7 @@ void finish()
Inputs: void (none) Inputs: void (none)
Description: Description:
************************************************************/ ************************************************************/
@ -1236,7 +1236,7 @@ void print_per_system_stats( void )
else else
fprintf( stderr, " -" ); fprintf( stderr, " -" );
} }
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
} }
else { else {
@ -1257,17 +1257,17 @@ void print_per_system_stats( void )
fprintf( stderr, " xmt/rcv/%%return = %d/%d/%d%%", fprintf( stderr, " xmt/rcv/%%return = %d/%d/%d%%",
h->num_sent, h->num_recv, h->num_sent, h->num_recv,
( ( h->num_recv * 100 ) / h->num_sent ) ); ( ( h->num_recv * 100 ) / h->num_sent ) );
} }
if( h->num_recv ) { if( h->num_recv ) {
avg = h->total_time / h->num_recv; avg = h->total_time / h->num_recv;
fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply ) ); fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply ) );
fprintf( stderr, "/%s", sprint_tm( avg ) ); fprintf( stderr, "/%s", sprint_tm( avg ) );
fprintf( stderr, "/%s", sprint_tm( h->max_reply ) ); fprintf( stderr, "/%s", sprint_tm( h->max_reply ) );
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
@ -1280,7 +1280,7 @@ void print_per_system_stats( void )
fprintf( stderr, " %s", sprint_tm( resp ) ); fprintf( stderr, " %s", sprint_tm( resp ) );
else else
fprintf( stderr, " -" ); fprintf( stderr, " -" );
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
} }
@ -1389,7 +1389,7 @@ void print_netdata( void )
Inputs: void (none) Inputs: void (none)
Description: Description:
************************************************************/ ************************************************************/
@ -1444,13 +1444,13 @@ void print_per_system_splits( void )
fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply_i ) ); fprintf( stderr, ", min/avg/max = %s", sprint_tm( h->min_reply_i ) );
fprintf( stderr, "/%s", sprint_tm( avg ) ); fprintf( stderr, "/%s", sprint_tm( avg ) );
fprintf( stderr, "/%s", sprint_tm( h->max_reply_i ) ); fprintf( stderr, "/%s", sprint_tm( h->max_reply_i ) );
} }
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
h->num_sent_i = h->num_recv_i = h->max_reply_i = h->num_sent_i = h->num_recv_i = h->max_reply_i =
h->min_reply_i = h->total_time_i = 0; h->min_reply_i = h->total_time_i = 0;
} }
} /* print_per_system_splits() */ } /* print_per_system_splits() */
@ -1464,7 +1464,7 @@ void print_per_system_splits( void )
Inputs: void (none) Inputs: void (none)
Description: Description:
************************************************************/ ************************************************************/
@ -1489,7 +1489,7 @@ void print_global_stats( void )
max_reply = 0; max_reply = 0;
total_replies = 1; total_replies = 1;
sum_replies = 0; sum_replies = 0;
}/* IF */ }/* IF */
fprintf( stderr, " %s ms (min round trip time)\n", sprint_tm( min_reply ) ); fprintf( stderr, " %s ms (min round trip time)\n", sprint_tm( min_reply ) );
@ -1546,7 +1546,7 @@ int send_ping( int s, HOST_ENTRY *h )
if( verbose_flag ) { if( verbose_flag ) {
print_warning( "%s: error while sending ping: %s\n", h->host, strerror( errno ) ); print_warning( "%s: error while sending ping: %s\n", h->host, strerror( errno ) );
} }
if( !loop_flag ) if( !loop_flag )
h->resp_times[h->num_sent] = RESP_ERROR; h->resp_times[h->num_sent] = RESP_ERROR;
@ -1724,7 +1724,7 @@ int decode_icmp_ipv4(
} }
getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
switch(icp->icmp_type) { switch(icp->icmp_type) {
case ICMP_UNREACH: case ICMP_UNREACH:
h = table[seqmap_value->host_nr]; h = table[seqmap_value->host_nr];
@ -1827,7 +1827,7 @@ int decode_icmp_ipv6(
} }
getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); getnameinfo(response_addr, response_addr_len, addr_ascii, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
switch(icp->icmp6_type) { switch(icp->icmp6_type) {
case ICMP_UNREACH: case ICMP_UNREACH:
h = table[seqmap_value->host_nr]; h = table[seqmap_value->host_nr];
@ -1922,7 +1922,7 @@ int wait_for_reply(long wait_time)
if(result <= 0) { if(result <= 0) {
return 0; return 0;
} }
gettimeofday( &current_time, &tz ); gettimeofday( &current_time, &tz );
// Process ICMP packet and retrieve id/seq // Process ICMP packet and retrieve id/seq
@ -2010,19 +2010,19 @@ int wait_for_reply(long wait_time)
fprintf( stderr, " [<- %s]", buf); fprintf( stderr, " [<- %s]", buf);
} }
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
}/* IF */ }/* IF */
}/* IF */ }/* IF */
else else
h->resp_times[this_count] = this_reply; h->resp_times[this_count] = this_reply;
}/* IF */ }/* IF */
else else
{ {
/* count is out of bounds?? */ /* count is out of bounds?? */
fprintf( stderr, "%s : duplicate for [%d], %d bytes, %s ms\n", fprintf( stderr, "%s : duplicate for [%d], %d bytes, %s ms\n",
h->host, this_count, result, sprint_tm( this_reply ) ); h->host, this_count, result, sprint_tm( this_reply ) );
}/* ELSE */ }/* ELSE */
}/* IF */ }/* IF */
@ -2046,7 +2046,7 @@ int wait_for_reply(long wait_time)
} }
printf( "\n" ); printf( "\n" );
}/* IF */ }/* IF */
}/* IF */ }/* IF */
@ -2061,7 +2061,7 @@ int wait_for_reply(long wait_time)
printf( "%s%s : [%d], %d bytes, %s ms", printf( "%s%s : [%d], %d bytes, %s ms",
h->host, h->pad, this_count, result, sprint_tm( this_reply ) ); h->host, h->pad, this_count, result, sprint_tm( this_reply ) );
printf( " (%s avg, ", sprint_tm( avg ) ); printf( " (%s avg, ", sprint_tm( avg ) );
if( h->num_recv <= h->num_sent ) { if( h->num_recv <= h->num_sent ) {
printf( "%d%% loss)", printf( "%d%% loss)",
( ( h->num_sent - h->num_recv ) * 100 ) / h->num_sent ); ( ( h->num_sent - h->num_recv ) * 100 ) / h->num_sent );
@ -2070,7 +2070,7 @@ int wait_for_reply(long wait_time)
else { else {
printf( "%d%% return)", printf( "%d%% return)",
( h->num_recv_total * 100 ) / h->num_sent ); ( h->num_recv_total * 100 ) / h->num_sent );
} }
if(addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) { if(addr_cmp((struct sockaddr *)&response_addr, (struct sockaddr *)&h->saddr)) {
@ -2078,9 +2078,9 @@ int wait_for_reply(long wait_time)
getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); getnameinfo((struct sockaddr *)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST);
fprintf( stderr, " [<- %s]", buf); fprintf( stderr, " [<- %s]", buf);
} }
printf( "\n" ); printf( "\n" );
}/* IF */ }/* IF */
/* remove this job, if we are done */ /* remove this job, if we are done */
@ -2089,7 +2089,7 @@ int wait_for_reply(long wait_time)
{ {
remove_job(h); remove_job(h);
} }
fflush( stdout ); fflush( stdout );
return num_jobs; return num_jobs;
@ -2242,10 +2242,10 @@ void add_addr( char *name, char *host, struct sockaddr *ipaddr, socklen_t ipaddr
i = ( int* )malloc( trials * sizeof( int ) ); i = ( int* )malloc( trials * sizeof( int ) );
if( !i ) if( !i )
crash_and_burn( "can't allocate resp_times array" ); crash_and_burn( "can't allocate resp_times array" );
for( n = 1; n < trials; n++ ) for( n = 1; n < trials; n++ )
i[n] = RESP_UNUSED; i[n] = RESP_UNUSED;
p->resp_times = i; p->resp_times = i;
}/* IF */ }/* IF */
@ -2257,12 +2257,12 @@ void add_addr( char *name, char *host, struct sockaddr *ipaddr, socklen_t ipaddr
i = ( int* )malloc( trials * sizeof( int ) ); i = ( int* )malloc( trials * sizeof( int ) );
if( !i ) if( !i )
crash_and_burn( "can't allocate sent_times array" ); crash_and_burn( "can't allocate sent_times array" );
for( n = 1; n < trials; n++ ) for( n = 1; n < trials; n++ )
i[n] = RESP_UNUSED; i[n] = RESP_UNUSED;
p->sent_times = i; p->sent_times = i;
}/* IF */ }/* IF */
#endif /* DEBUG || _DEBUG */ #endif /* DEBUG || _DEBUG */
@ -2315,12 +2315,12 @@ void remove_job( HOST_ENTRY *h )
Description: Description:
************************************************************/ ************************************************************/
void crash_and_burn( char *message ) void crash_and_burn( char *message )
{ {
if( verbose_flag ) if( verbose_flag )
fprintf( stderr, "%s: %s\n", prog, message ); fprintf( stderr, "%s: %s\n", prog, message );
exit( 4 ); exit( 4 );
} /* crash_and_burn() */ } /* crash_and_burn() */

Loading…
Cancel
Save