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 *resp_times; /* individual response times */
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_count; /* how many timeout occurred */
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_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
* preallocate here two struct events for each ping that we might send for
* this host. */

@ -2136,16 +2136,31 @@ int decode_icmp_ipv4(
switch (icp->icmp_type) {
case ICMP_UNREACH:
h = table[seqmap_value->host_nr];
if (icp->icmp_code > ICMP_UNREACH_MAXTYPE) {
print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
addr_ascii, h->host);
}
else {
print_warning("%s from %s for ICMP Echo sent to %s",
icmp_unreach_str[icp->icmp_code], addr_ascii, h->host);
}
print_warning("\n");
if ( top_view == 0 ){
if (icp->icmp_code > ICMP_UNREACH_MAXTYPE) {
print_warning("ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
addr_ascii, h->host);
}
else {
print_warning("%s from %s for ICMP Echo sent to %s",
icmp_unreach_str[icp->icmp_code], addr_ascii, h->host);
}
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++;
break;

@ -54,14 +54,15 @@ void top_view_end( void ){
#define HOST_POS 2
#define SEND_POS 20
#define RECV_POS 30
#define LOST_POS 40
#define TIMEOUT_POS 50
#define HOST_POS 2
#define SEND_POS 20
#define RECV_POS 30
#define LOST_POS 40
#define TIMEOUT_POS 50
#define TIMEOUT_TOTAL_POS 60
#define TIMEOUT_SEQ_POS 70
#define TIMEOUT_TIME_POS 80
#define TIMEOUT_SEQ_POS 70
#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_SEQ_POS , "seq");
pos_printf( 4 , TIMEOUT_TIME_POS , "time");
pos_printf( 4 , ICMP_MSG_POS , "ICMP msg");
}
@ -126,15 +130,16 @@ void top_view_print( HOST_ENTRY *h, int timeout ) {
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, 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, LOST_POS , "%d", ( h->num_sent - h->num_recv ));
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, 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, 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_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);
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);

Loading…
Cancel
Save