code cleanup and ICMP Error message handling

pull/291/head
lordrasmus 2 years ago
parent b3b6604f55
commit bd3fd0d5e1

@ -28,12 +28,16 @@ typedef struct host_entry {
int64_t total_time_i; /* sum of response times */ int64_t total_time_i; /* sum of response times */
int64_t *resp_times; /* individual response times */ int64_t *resp_times; /* individual response times */
int top_view_print_pos; /* line where the host is printed */ int top_view_print_pos; /* line where the host is printed */
int64_t top_view_last_timeouts; /* timeout Counter */ int64_t top_view_last_timeouts; /* timeout Counter */
int64_t top_view_last_timeouts_count; /* how many timeout occurred */ int64_t top_view_last_timeouts_count; /* how many timeout occurred */
int64_t top_view_last_timeouts_seq; /* how many packets where lost till the next answer arrived */ int64_t top_view_last_timeouts_seq; /* how many packets where lost till the next answer arrived */
char top_view_last_timeout_time[100]; /* buffer to print how long the last timeout was ( packets * period ) */ char top_view_last_timeout_time[100]; /* buffer to print how long the last timeout was ( packets * period ) */
char top_view_icmp_message[200]; /* buffer to print how long the last timeout was ( packets * period ) */
/* to avoid allocating two struct events each time that we send a ping, we /* to avoid allocating two struct events each time that we send a ping, we
* preallocate here two struct events for each ping that we might send for * preallocate here two struct events for each ping that we might send for
* this host. */ * this host. */

@ -2136,6 +2136,9 @@ int decode_icmp_ipv4(
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];
if ( top_view == 0 ){
if (icp->icmp_code > ICMP_UNREACH_MAXTYPE) { if (icp->icmp_code > ICMP_UNREACH_MAXTYPE) {
print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s", print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
addr_ascii, h->host); addr_ascii, h->host);
@ -2146,6 +2149,18 @@ int decode_icmp_ipv4(
} }
print_warning("\n"); print_warning("\n");
}else{
if (icp->icmp_code > ICMP_UNREACH_MAXTYPE) {
sprintf( h->top_view_icmp_message,"ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
addr_ascii, h->host);
}
else {
sprintf( h->top_view_icmp_message,"%s from %s for ICMP Echo sent to %s",
icmp_unreach_str[icp->icmp_code], addr_ascii, h->host);
}
}
num_othericmprcvd++; num_othericmprcvd++;
break; break;

@ -62,6 +62,7 @@ void top_view_end( void ){
#define TIMEOUT_TOTAL_POS 60 #define TIMEOUT_TOTAL_POS 60
#define TIMEOUT_SEQ_POS 70 #define TIMEOUT_SEQ_POS 70
#define TIMEOUT_TIME_POS 80 #define TIMEOUT_TIME_POS 80
#define ICMP_MSG_POS 90
@ -90,6 +91,9 @@ static void print_top_view_init( void ){
pos_printf( 4 , TIMEOUT_TOTAL_POS , "total"); pos_printf( 4 , TIMEOUT_TOTAL_POS , "total");
pos_printf( 4 , TIMEOUT_SEQ_POS , "seq"); pos_printf( 4 , TIMEOUT_SEQ_POS , "seq");
pos_printf( 4 , TIMEOUT_TIME_POS , "time"); pos_printf( 4 , TIMEOUT_TIME_POS , "time");
pos_printf( 4 , ICMP_MSG_POS , "ICMP msg");
} }
@ -127,14 +131,15 @@ void top_view_print( HOST_ENTRY *h, int timeout ) {
line_clear( 5 + h->top_view_print_pos ); line_clear( 5 + h->top_view_print_pos );
pos_printf( 5 + h->top_view_print_pos, HOST_POS , "%s", h->host); pos_printf( 5 + h->top_view_print_pos, HOST_POS , "%s", h->host);
pos_printf( 5 + h->top_view_print_pos, SEND_POS , "%d", h->num_sent); pos_printf( 5 + h->top_view_print_pos, SEND_POS , "%d", h->num_sent);
pos_printf( 5 + h->top_view_print_pos, RECV_POS , "%d", h->num_recv); pos_printf( 5 + h->top_view_print_pos, RECV_POS , "%d", h->num_recv);
pos_printf( 5 + h->top_view_print_pos, LOST_POS , "%d", ( h->num_sent - h->num_recv )); pos_printf( 5 + h->top_view_print_pos, LOST_POS , "%d", ( h->num_sent - h->num_recv ));
pos_printf( 5 + h->top_view_print_pos, TIMEOUT_TOTAL_POS , "%"PRIi64, h->top_view_last_timeouts_count); pos_printf( 5 + h->top_view_print_pos, TIMEOUT_TOTAL_POS , "%"PRIi64, h->top_view_last_timeouts_count);
pos_printf( 5 + h->top_view_print_pos, TIMEOUT_SEQ_POS , "%"PRIi64, h->top_view_last_timeouts_seq); pos_printf( 5 + h->top_view_print_pos, TIMEOUT_SEQ_POS , "%"PRIi64, h->top_view_last_timeouts_seq);
pos_printf( 5 + h->top_view_print_pos, TIMEOUT_TIME_POS , "%s", h->top_view_last_timeout_time); pos_printf( 5 + h->top_view_print_pos, TIMEOUT_TIME_POS , "%s", h->top_view_last_timeout_time);
pos_printf( 5 + h->top_view_print_pos, ICMP_MSG_POS , "%s", h->top_view_icmp_message);

Loading…
Cancel
Save