/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/26 17:03:11 by tomoron #+# #+# */ /* Updated: 2025/05/02 01:07:37 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/ft_ping.h" int add_host(t_settings *res, char *host) { t_host_list *new; t_host_list *tmp; new = malloc(sizeof(t_host_list)); if(!new) return(0); new->host = host; new->next = 0; tmp = res->hosts; while(tmp && tmp->next) tmp = tmp->next; if(tmp) tmp->next = new; else res->hosts = new; return(1); } void free_hosts(t_host_list *list) { t_host_list *tmp; while(list) { tmp = list->next; free(list); list = tmp; } } double timediff(struct timeval *from) { struct timeval now; float diff; gettimeofday(&now, 0); diff = ((double)now.tv_sec - from->tv_sec); diff += (((double)now.tv_usec / 1000000) - ((double)from->tv_usec / 1000000)); return(diff); }