add: error message
This commit is contained in:
31
src/print.c
31
src/print.c
@@ -1,8 +1,10 @@
|
||||
|
||||
|
||||
#include "icmp_error.h"
|
||||
#include "interval.h"
|
||||
#include "setting.h"
|
||||
#include "statistics.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <bits/types/struct_timeval.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
@@ -47,16 +49,35 @@ void print_statistics(struct statistics const *stats, struct setting const *sett
|
||||
stats->packets_received,
|
||||
(double) stats->packets_received * 100 / (double) stats->packets_sent
|
||||
);
|
||||
// TODO fix packet lost calcul
|
||||
}
|
||||
|
||||
void print_recv(const struct setting *settings, const struct icmphdr *header, const struct timeval *start, const struct timeval *stop)
|
||||
static const char *get_message_description(const uint8_t type, const uint8_t code)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case 0:
|
||||
return "icmp_seq=%d ttl=%d time=%.3f ms";
|
||||
case ICMP_DEST_UNREACH:
|
||||
return (net_icmp_unreach_messages[code]);
|
||||
case ICMP_REDIRECT:
|
||||
return (net_icmp_redirect_messages[code]);
|
||||
case ICMP_TIME_EXCEEDED:
|
||||
return (net_icmp_time_messages[code]);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
printf("%zu bytes from %s: icmp_seq=%d ttl=%d time=%.3f ms\n",
|
||||
settings->payload_size + sizeof(struct icmphdr),
|
||||
settings->dest.ipstr,
|
||||
void print_recv(const struct setting *settings, const struct icmphdr *header, const struct timeval *start, const struct timeval *stop, struct sockaddr_in const *sender)
|
||||
{
|
||||
char *ipstr = inet_ntoa(sender->sin_addr);
|
||||
printf("%zu", settings->payload_size + sizeof(struct icmphdr) + ((header->type == 0) ? 0 : sizeof(struct iphdr)));
|
||||
printf(" bytes from %s: ", ipstr);
|
||||
printf(get_message_description(header->type, header->code),
|
||||
htons(header->un.echo.sequence),
|
||||
settings->ttl,
|
||||
get_interval(start, stop)
|
||||
);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user