Files
ft_ping/srcs/waitlist_utils.c

64 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* waitlist_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/01 17:38:58 by tomoron #+# #+# */
/* Updated: 2025/08/08 22:24:42 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_ping.h"
void waitlist_add(t_waitlist **waitlist, t_waitlist *elem)
{
t_waitlist *cur;
cur = *waitlist;
while(cur && cur->next)
cur = cur->next;
if(cur)
cur->next = elem;
else
*waitlist = elem;
}
void waitlist_free(t_waitlist *lst)
{
t_waitlist *tmp;
while(lst)
{
tmp = lst->next;
free(lst);
lst = tmp;
}
}
t_waitlist *waitlist_remove(t_waitlist **lst, t_icmp_ip_reply *res, int is_ttl_exceeded)
{
t_waitlist *prev;
t_waitlist *cur;
prev = 0;
cur = *lst;
if(is_ttl_exceeded)
res = (void *)res + sizeof(struct iphdr) + 8;
res->icmp.sequence = htons(res->icmp.sequence);
while(cur && cur->seq != res->icmp.sequence)
{
prev = cur;
cur = cur->next;
}
if(!cur)
return (0);
if(!prev)
*lst = cur->next;
else
prev->next = cur->next;
return(cur);
}