Don't output ICMP errors with -q option (#1)

pull/19/head
Andreas Jaggi 13 years ago
parent 063ee44417
commit 8e57b6f43f

@ -1901,57 +1901,59 @@ int handle_random_icmp( FPING_ICMPHDR *p, int psize, FPING_SOCKADDR *addr )
#endif #endif
{ {
case ICMP_UNREACH: case ICMP_UNREACH:
sent_icmp = ( FPING_ICMPHDR* )( c + 28 ); if( !quiet_flag ) {
sent_icmp = ( FPING_ICMPHDR* )( c + 28 );
#ifndef IPV6 #ifndef IPV6
sent_icmp = ( struct icmp* )( c + 28 ); sent_icmp = ( struct icmp* )( c + 28 );
if( ( sent_icmp->icmp_type == ICMP_ECHO ) && if( ( sent_icmp->icmp_type == ICMP_ECHO ) &&
( ntohs(sent_icmp->icmp_id) == ident ) && ( ntohs(sent_icmp->icmp_id) == ident ) &&
( ntohs(sent_icmp->icmp_seq) <= ( n_short )max_seq_sent ) ) ( ntohs(sent_icmp->icmp_seq) <= ( n_short )max_seq_sent ) )
{
/* this is a response to a ping we sent */
h = table[ntohs(sent_icmp->icmp_seq) % num_hosts];
if( p->icmp_code > ICMP_UNREACH_MAXTYPE )
{ {
fprintf( stderr, "ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s", /* this is a response to a ping we sent */
inet_ntoa( addr->sin_addr ), h->host ); h = table[ntohs(sent_icmp->icmp_seq) % num_hosts];
#else if( p->icmp_code > ICMP_UNREACH_MAXTYPE )
if( ( sent_icmp->icmp6_type == ICMP_ECHO ) && {
( ntohs(sent_icmp->icmp6_id) == ident ) && fprintf( stderr, "ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
( ntohs(sent_icmp->icmp6_seq) <= ( n_short )max_seq_sent ) ) inet_ntoa( addr->sin_addr ), h->host );
{
/* this is a response to a ping we sent */
h = table[ntohs(sent_icmp->icmp6_seq) % num_hosts];
if( p->icmp6_code > ICMP_UNREACH_MAXTYPE ) #else
if( ( sent_icmp->icmp6_type == ICMP_ECHO ) &&
( ntohs(sent_icmp->icmp6_id) == ident ) &&
( ntohs(sent_icmp->icmp6_seq) <= ( n_short )max_seq_sent ) )
{ {
fprintf( stderr, "ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s", /* this is a response to a ping we sent */
addr_ascii, h->host ); h = table[ntohs(sent_icmp->icmp6_seq) % num_hosts];
if( p->icmp6_code > ICMP_UNREACH_MAXTYPE )
{
fprintf( stderr, "ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
addr_ascii, h->host );
#endif #endif
}/* IF */ }/* IF */
else else
{ {
fprintf( stderr, "%s from %s for ICMP Echo sent to %s", fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
#ifndef IPV6 #ifndef IPV6
icmp_unreach_str[p->icmp_code], inet_ntoa( addr->sin_addr ), h->host ); icmp_unreach_str[p->icmp_code], inet_ntoa( addr->sin_addr ), h->host );
#else #else
icmp_unreach_str[p->icmp6_code], addr_ascii, h->host ); icmp_unreach_str[p->icmp6_code], addr_ascii, h->host );
#endif #endif
}/* ELSE */ }/* ELSE */
if( inet_addr( h->host ) == -1 ) if( inet_addr( h->host ) == -1 )
#ifndef IPV6 #ifndef IPV6
fprintf( stderr, " (%s)", inet_ntoa( h->saddr.sin_addr ) ); fprintf( stderr, " (%s)", inet_ntoa( h->saddr.sin_addr ) );
#else #else
fprintf( stderr, " (%s)", addr_ascii); fprintf( stderr, " (%s)", addr_ascii);
#endif #endif
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
}/* IF */
}/* IF */ }/* IF */
return 1; return 1;
@ -1960,35 +1962,37 @@ int handle_random_icmp( FPING_ICMPHDR *p, int psize, FPING_SOCKADDR *addr )
case ICMP_REDIRECT: case ICMP_REDIRECT:
case ICMP_TIMXCEED: case ICMP_TIMXCEED:
case ICMP_PARAMPROB: case ICMP_PARAMPROB:
sent_icmp = ( FPING_ICMPHDR* )( c + 28 ); if( !quiet_flag ) {
sent_icmp = ( FPING_ICMPHDR* )( c + 28 );
#ifndef IPV6 #ifndef IPV6
if( ( sent_icmp->icmp_type == ICMP_ECHO ) && if( ( sent_icmp->icmp_type == ICMP_ECHO ) &&
( ntohs(sent_icmp->icmp_id) == ident ) && ( ntohs(sent_icmp->icmp_id) == ident ) &&
( ntohs(sent_icmp->icmp_seq) <= ( n_short )max_seq_sent ) ) ( ntohs(sent_icmp->icmp_seq) <= ( n_short )max_seq_sent ) )
{ {
/* this is a response to a ping we sent */ /* this is a response to a ping we sent */
h = table[ntohs(sent_icmp->icmp_seq) % num_hosts]; h = table[ntohs(sent_icmp->icmp_seq) % num_hosts];
fprintf( stderr, "%s from %s for ICMP Echo sent to %s", fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
icmp_type_str[p->icmp_type], inet_ntoa( addr->sin_addr ), h->host ); icmp_type_str[p->icmp_type], inet_ntoa( addr->sin_addr ), h->host );
if( inet_addr( h->host ) == -1 ) if( inet_addr( h->host ) == -1 )
fprintf( stderr, " (%s)", inet_ntoa( h->saddr.sin_addr ) ); fprintf( stderr, " (%s)", inet_ntoa( h->saddr.sin_addr ) );
#else #else
if( ( sent_icmp->icmp6_type == ICMP_ECHO ) && if( ( sent_icmp->icmp6_type == ICMP_ECHO ) &&
( ntohs(sent_icmp->icmp6_id) == ident ) && ( ntohs(sent_icmp->icmp6_id) == ident ) &&
( ntohs(sent_icmp->icmp6_seq) <= ( n_short )max_seq_sent ) ) ( ntohs(sent_icmp->icmp6_seq) <= ( n_short )max_seq_sent ) )
{ {
/* this is a response to a ping we sent */ /* this is a response to a ping we sent */
h = table[ntohs(sent_icmp->icmp6_seq) % num_hosts]; h = table[ntohs(sent_icmp->icmp6_seq) % num_hosts];
fprintf( stderr, "%s from %s for ICMP Echo sent to %s", fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
icmp_type_str[p->icmp6_type], addr_ascii, h->host ); icmp_type_str[p->icmp6_type], addr_ascii, h->host );
if( inet_addr( h->host ) == -1 ) if( inet_addr( h->host ) == -1 )
fprintf( stderr, " (%s)", addr_ascii ); fprintf( stderr, " (%s)", addr_ascii );
#endif #endif
fprintf( stderr, "\n" ); fprintf( stderr, "\n" );
}/* IF */
}/* IF */ }/* IF */
return 2; return 2;

Loading…
Cancel
Save