Fixed issue when 0 packets are sent

This commit is contained in:
vauden
2024-11-06 00:38:46 +01:00
parent f45a755633
commit 00fcdacf31
3 changed files with 6 additions and 2 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
*.o
a.out
.vscode

2
main.c
View File

@@ -42,7 +42,7 @@ void ft_recv(int sock, uint16_t seq, char *ip, double start)
time = (get_timestamp() - start) * 1000;
checksum = icmp_hdr->checksum;
icmp_hdr->checksum = 0;
if (icmp_hdr->seq != seq || calculate_checksum((uint16_t *)icmp_hdr, sizeof(*icmp_hdr)) != checksum)
if (icmp_hdr->seq != seq || calculate_checksum((uint16_t *)icmp_hdr, sizeof(*icmp_hdr)) != checksum) // if checksum or sequence is invalid
return;
fill_timestamp_array(&stats, time);
stats.n_packet_recv++;

View File

@@ -68,6 +68,8 @@ double get_avg(double *timestamp_array)
double avg = 0;
int i = 0;
if (timestamp_array[0] == 0)
return (0);
while (timestamp_array[i])
{
avg += timestamp_array[i];