Add: error manager

Added function to print errors corresponding to the packet type and code values
This commit is contained in:
vauden
2024-11-19 18:51:04 +01:00
parent 26d9f40030
commit 6cd5b0618d
6 changed files with 183 additions and 39 deletions

View File

@@ -8,18 +8,15 @@
#include <math.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#define PACKET_SIZE 64
struct icmp_header
struct net_icmp_header
{
uint8_t type;
uint8_t code;
@@ -28,6 +25,14 @@ struct icmp_header
uint16_t seq;
};
struct net_packet
{
uint8_t data[PACKET_SIZE];
int n_bytes;
struct sockaddr_in addr;
struct net_icmp_header *icmp_hdr;
};
struct packet_stats
{
uint16_t n_packet_sent;
@@ -43,11 +48,13 @@ struct flags
double interval;
int preload_count;
int count;
int ttl;
};
// PACKET UTILS
uint16_t make_checksum(uint16_t *data, int len);
struct in_addr get_addr_by_hostname(char *hostname);
bool parse_packet(struct net_packet packet, uint16_t seq, uint16_t checksum);
// MATH
double get_stddev(const double *timestamp_array);
@@ -59,6 +66,7 @@ long ft_atoi(const char *nptr);
// VERBOSE
void print_help(void);
bool parse_opt(int argc, char **argv, struct flags *flags);
void print_packet_error(struct net_packet packet);
// STATS
void print_recap(char *ip, const struct packet_stats stats);