make timeout work, add setcap makefile rule
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/26 19:54:25 by tomoron #+# #+# */
|
||||
/* Updated: 2025/08/22 15:45:44 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/08/24 19:44:50 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -67,11 +67,18 @@ void ping_end_print(t_settings *set, char *host, t_stats *stats)
|
||||
printf("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n", stats->min, stats->avg, stats->max, stddev);
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
int timeout_check(t_settings *set)
|
||||
{
|
||||
if (set->timeout == -1)
|
||||
return (1);
|
||||
return (timediff(&set->start_time) - 0.001 <= set->timeout);
|
||||
}
|
||||
|
||||
int ping_host(t_settings *set, char *host)
|
||||
{
|
||||
uint16_t seq;
|
||||
struct addrinfo *info;
|
||||
struct timeval last_sent;
|
||||
t_waitlist *wl;
|
||||
t_waitlist *tmp;
|
||||
t_stats stats;
|
||||
@ -81,20 +88,20 @@ int ping_host(t_settings *set, char *host)
|
||||
info = resolve_ip(host, set);
|
||||
if(!info)
|
||||
return(0);
|
||||
last_sent.tv_sec = 0;
|
||||
last_sent.tv_usec = 0;
|
||||
wl = 0;
|
||||
inet_ntop(info->ai_family, (void *)&((struct sockaddr_in *)(info->ai_addr))->sin_addr, set->current_ip, sizeof(set->current_ip));
|
||||
ping_start_print(set, host);
|
||||
ping_start_print(set, host);
|
||||
while ((seq < set->count || set->count == 0) && !g_stop)
|
||||
{
|
||||
tmp = send_icmp(set, info, &seq, &last_sent, &stats);
|
||||
tmp = send_icmp(set, info, &seq, &stats);
|
||||
if(tmp)
|
||||
waitlist_add(&wl, tmp);
|
||||
usleep(100);
|
||||
if (!timeout_check(set))
|
||||
break ;
|
||||
usleep(10);
|
||||
receive_icmp(set, &wl, &stats);
|
||||
}
|
||||
while(wl && !g_stop && timediff(&set->last_send_time) < set->linger)
|
||||
while(wl && !g_stop && timediff(&set->last_send_time) < set->linger && timeout_check(set))
|
||||
receive_icmp(set, &wl, &stats);
|
||||
ping_end_print(set, host, &stats);
|
||||
freeaddrinfo(info);
|
||||
@ -107,6 +114,7 @@ void send_pings(t_settings *set)
|
||||
t_host_list *cur;
|
||||
|
||||
cur = set->hosts;
|
||||
gettimeofday(&set->start_time, 0);
|
||||
if(set->setTtl)
|
||||
setsockopt(set->socket, IPPROTO_IP, IP_TTL, &set->ttl, sizeof(set->ttl));
|
||||
while(cur)
|
||||
|
Reference in New Issue
Block a user