From abb1d1f3646f74d05753ecd2cac8a87ddc58e8b1 Mon Sep 17 00:00:00 2001 From: 0x35c <> Date: Sat, 31 May 2025 17:18:21 +0200 Subject: [PATCH] fix: ports parsing and change timeout to 5s for no_response --- include/response.h | 2 +- src/parsing.c | 2 +- src/scan.c | 4 ++-- src/thread.c | 20 ++++---------------- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/include/response.h b/include/response.h index 510c664..938c671 100644 --- a/include/response.h +++ b/include/response.h @@ -7,7 +7,7 @@ #include "scan.h" -#define TIMEOUT 1 +#define TIMEOUT 5 typedef enum { CLOSED, diff --git a/src/parsing.c b/src/parsing.c index 6226a3b..85e80f3 100644 --- a/src/parsing.c +++ b/src/parsing.c @@ -57,7 +57,7 @@ int parse_ports(const char *arg, uint16_t *p_start, uint16_t *p_end) { size_t i = 0; if (!arg) - return -1; + return 0; for (; isdigit(arg[i]); i++) ; int start = atoi(arg); diff --git a/src/scan.c b/src/scan.c index a2bc280..5e10b02 100644 --- a/src/scan.c +++ b/src/scan.c @@ -43,13 +43,13 @@ static int send_recv_packet(const struct scan *data, int sockfd, pcap_t *handle) { send_packet(data, sockfd); uint8_t timer = 0; - for (; timer < TIMEOUT * 100; timer++) { + for (; timer < TIMEOUT * 10; timer++) { if (pcap_dispatch(handle, 1, dispatch_callback, (u_char *)data)) break; usleep(100000); } pcap_breakloop(handle); - if (timer == TIMEOUT * 100) { + if (timer == TIMEOUT * 10) { no_response(data); return 0; } diff --git a/src/thread.c b/src/thread.c index 55dffbe..aeb5cc7 100644 --- a/src/thread.c +++ b/src/thread.c @@ -63,17 +63,6 @@ static struct thread *init_threads_data(const struct option_lst *options, } for (uint8_t i = 0; i < nb_threads; i++) { memcpy(&threads[i].host, host, sizeof(struct host)); - threads[i].port_start = 1; - threads[i].port_end = 1024; - if (option_isset(options, FL_FAST)) - threads[i].port_end = 128; - const char *ports = get_option_arg(options, FL_PORTS); - if (parse_ports(ports, &threads[i].port_start, - &threads[i].port_end) < 0) { - if (!option_isset(options, FL_FAST)) - goto error; - threads[i].port_end = 128; - } threads[i].type = parse_type(get_option_arg(options, FL_SCAN)); if (threads[i].type < 0) goto error; @@ -100,12 +89,11 @@ int create_threads(const struct option_lst *options, char *ip_addr, uint16_t port_start = 1; uint16_t port_end = 1024; - const char *ports = get_option_arg(options, FL_PORTS); - if (parse_ports(ports, &port_start, &port_end) < 0) { - if (!option_isset(options, FL_FAST)) - return -1; + if (option_isset(options, FL_FAST)) port_end = 128; - } + const char *ports = get_option_arg(options, FL_PORTS); + if (parse_ports(ports, &port_start, &port_end) < 0) + return -1; const char *nb_threads_str = get_option_arg(options, FL_SPEEDUP); if (!nb_threads_str) {