remove forbidden function fcntl, add early stop for errors during parsing, remove debug print
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 22:49:22 by tomoron #+# #+# */
|
||||
/* Updated: 2025/06/03 00:40:54 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/08/08 22:19:52 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "includes/ft_ping.h"
|
||||
@ -72,7 +72,7 @@ t_waitlist *send_icmp(t_settings *set, struct addrinfo *host, uint16_t *seq, str
|
||||
if(timediff(last) < set->interval)
|
||||
return (0);
|
||||
packet = prepare_icmp_echo(*seq, set->id);
|
||||
len = sendto(set->socket, &packet, sizeof(t_icmp_echo), 0, host->ai_addr, host->ai_addrlen);
|
||||
len = sendto(set->socket, &packet, sizeof(t_icmp_echo), MSG_DONTWAIT, host->ai_addr, host->ai_addrlen);
|
||||
if(len == (size_t)-1)
|
||||
{
|
||||
perror(set->name);
|
||||
@ -137,7 +137,7 @@ void receive_icmp(t_settings *set, t_waitlist **wl, t_stats *stats)
|
||||
uint16_t checksum;
|
||||
t_waitlist *elem;
|
||||
|
||||
len = recvfrom(set->socket, &buffer, 1024, 0, 0, 0);
|
||||
len = recv(set->socket, &buffer, 1024, MSG_DONTWAIT);
|
||||
|
||||
res = (void *)buffer;
|
||||
if(len == (size_t)-1 )
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/24 00:03:56 by tomoron #+# #+# */
|
||||
/* Updated: 2025/05/02 00:51:39 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/08/08 22:30:18 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,7 +33,6 @@ int init_socket(char *name)
|
||||
fprintf(stderr, "%s: can't initialize socket\n", name);
|
||||
return(-1);
|
||||
}
|
||||
fcntl(res, F_SETFL, O_NONBLOCK);
|
||||
return(res);
|
||||
}
|
||||
|
||||
@ -60,12 +59,15 @@ int main(int argc, char **argv)
|
||||
t_settings settings;
|
||||
|
||||
settings = parse_args(argc, argv);
|
||||
if(settings.stop)
|
||||
goto early_stop;
|
||||
settings.socket = init_socket(argv[0]);
|
||||
settings.id = get_id();
|
||||
settings.name = argv[0];
|
||||
signal(SIGINT, signal_handler);
|
||||
if(settings.stop || settings.err || settings.socket == -1)
|
||||
{
|
||||
early_stop:
|
||||
free_hosts(settings.hosts);
|
||||
return((settings.err != 0) * 64);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/01 17:38:58 by tomoron #+# #+# */
|
||||
/* Updated: 2025/06/03 00:27:30 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/08/08 22:24:42 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -50,7 +50,6 @@ t_waitlist *waitlist_remove(t_waitlist **lst, t_icmp_ip_reply *res, int is_ttl_e
|
||||
res->icmp.sequence = htons(res->icmp.sequence);
|
||||
while(cur && cur->seq != res->icmp.sequence)
|
||||
{
|
||||
printf("%d, %d\n", cur->seq, res->icmp.sequence);
|
||||
prev = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
Reference in New Issue
Block a user