fix: ports parsing and change timeout to 5s for no_response

This commit is contained in:
0x35c 2025-05-31 17:18:21 +02:00
parent 6164363cce
commit abb1d1f364
4 changed files with 8 additions and 20 deletions

View File

@ -7,7 +7,7 @@
#include "scan.h" #include "scan.h"
#define TIMEOUT 1 #define TIMEOUT 5
typedef enum { typedef enum {
CLOSED, CLOSED,

View File

@ -57,7 +57,7 @@ int parse_ports(const char *arg, uint16_t *p_start, uint16_t *p_end)
{ {
size_t i = 0; size_t i = 0;
if (!arg) if (!arg)
return -1; return 0;
for (; isdigit(arg[i]); i++) for (; isdigit(arg[i]); i++)
; ;
int start = atoi(arg); int start = atoi(arg);

View File

@ -43,13 +43,13 @@ static int send_recv_packet(const struct scan *data, int sockfd, pcap_t *handle)
{ {
send_packet(data, sockfd); send_packet(data, sockfd);
uint8_t timer = 0; uint8_t timer = 0;
for (; timer < TIMEOUT * 100; timer++) { for (; timer < TIMEOUT * 10; timer++) {
if (pcap_dispatch(handle, 1, dispatch_callback, (u_char *)data)) if (pcap_dispatch(handle, 1, dispatch_callback, (u_char *)data))
break; break;
usleep(100000); usleep(100000);
} }
pcap_breakloop(handle); pcap_breakloop(handle);
if (timer == TIMEOUT * 100) { if (timer == TIMEOUT * 10) {
no_response(data); no_response(data);
return 0; return 0;
} }

View File

@ -63,17 +63,6 @@ static struct thread *init_threads_data(const struct option_lst *options,
} }
for (uint8_t i = 0; i < nb_threads; i++) { for (uint8_t i = 0; i < nb_threads; i++) {
memcpy(&threads[i].host, host, sizeof(struct host)); 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)); threads[i].type = parse_type(get_option_arg(options, FL_SCAN));
if (threads[i].type < 0) if (threads[i].type < 0)
goto error; 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_start = 1;
uint16_t port_end = 1024; uint16_t port_end = 1024;
const char *ports = get_option_arg(options, FL_PORTS); if (option_isset(options, FL_FAST))
if (parse_ports(ports, &port_start, &port_end) < 0) {
if (!option_isset(options, FL_FAST))
return -1;
port_end = 128; 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); const char *nb_threads_str = get_option_arg(options, FL_SPEEDUP);
if (!nb_threads_str) { if (!nb_threads_str) {