add --ttl and -v flag

This commit is contained in:
2025-06-01 22:11:57 +02:00
parent cc3cfa3d03
commit c2a00ab4b3
3 changed files with 11 additions and 4 deletions

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/26 19:54:25 by tomoron #+# #+# */ /* Created: 2025/04/26 19:54:25 by tomoron #+# #+# */
/* Updated: 2025/05/22 23:01:33 by tomoron ### ########.fr */ /* Updated: 2025/06/01 22:09:27 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,7 +40,10 @@ struct addrinfo *resolve_ip(char *host, t_settings *settings)
void ping_start_print(t_settings *set, char *host) void ping_start_print(t_settings *set, char *host)
{ {
printf("PING %s (%s): 56 data bytes\n", host, set->current_ip); printf("PING %s (%s): 56 data bytes", host, set->current_ip);
if(set->verbose)
printf(", id 0x%04x = %d", set->id, set->id);
printf("\n");
} }
void ping_end_print(t_settings *set, char *host, t_stats *stats) void ping_end_print(t_settings *set, char *host, t_stats *stats)
@ -100,6 +103,8 @@ void send_pings(t_settings *set)
t_host_list *cur; t_host_list *cur;
cur = set->hosts; cur = set->hosts;
if(set->setTtl)
setsockopt(set->socket, IPPROTO_IP, IP_TTL, &set->ttl, sizeof(set->ttl));
while(cur) while(cur)
{ {
if(!ping_host(set, cur->host)) if(!ping_host(set, cur->host))

View File

@ -56,6 +56,7 @@ typedef struct s_settings
int linger; //-W (--linger) int linger; //-W (--linger)
int ttl; // --ttl int ttl; // --ttl
short setTtl; // is ttl set short setTtl; // is ttl set
short verbose; // -v (--verbose)
int socket; int socket;
uint16_t id; uint16_t id;

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/26 17:01:53 by tomoron #+# #+# */ /* Created: 2025/04/26 17:01:53 by tomoron #+# #+# */
/* Updated: 2025/05/22 23:01:05 by tomoron ### ########.fr */ /* Updated: 2025/06/01 21:37:16 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "includes/ft_ping.h" #include "includes/ft_ping.h"
@ -96,6 +96,8 @@ void parse_opt(int *i, t_settings *set, int argc, char **argv)
show_help(set, *argv); show_help(set, *argv);
else if(!strcmp(argv[*i], "-c") || !strncmp(argv[*i], "--count", 7)) else if(!strcmp(argv[*i], "-c") || !strncmp(argv[*i], "--count", 7))
set->count = get_set_int(i, argc, argv, 7, set); set->count = get_set_int(i, argc, argv, 7, set);
else if(!strcmp(argv[*i], "-v") || !strncmp(argv[*i], "--verbose", 7))
set->verbose = 1;
else if(!strcmp(argv[*i], "-w") || !strncmp(argv[*i], "--timeout", 9)) else if(!strcmp(argv[*i], "-w") || !strncmp(argv[*i], "--timeout", 9))
set->timeout = get_set_int(i, argc, argv, 9, set); set->timeout = get_set_int(i, argc, argv, 9, set);
else if(!strcmp(argv[*i], "-W") || !strncmp(argv[*i], "--linger", 8)) else if(!strcmp(argv[*i], "-W") || !strncmp(argv[*i], "--linger", 8))
@ -166,4 +168,3 @@ t_settings parse_args(int argc, char **argv)
res.err = !check_values(&res, argv[0]); res.err = !check_values(&res, argv[0]);
return(res); return(res);
} }