core: use only one struct data instead of thead_data and scan_data

core: do parsing in the main, put all in struct general
fix: code support port > 1024
This commit is contained in:
2025-06-03 16:49:41 +02:00
parent d640c95224
commit 9ae1e29f71
12 changed files with 143 additions and 168 deletions

View File

@ -1,3 +1,4 @@
#include <stdint.h>
#include <stdio.h>
#include "parsing.h"
@ -9,11 +10,11 @@ void print_usage(void)
// TODO
}
static void print_port_state(const struct response *response, e_scantype type)
static void print_port_state(uint16_t port, e_scantype type, const struct response * response)
{
if (type != SCAN_ALL && response->states[type] == CLOSED)
return;
printf("%-5d %-12s ", response->port,
printf("%-5d %-12s ", port,
response->service ? response->service : "Unassigned");
if (type == SCAN_ALL)
for (e_scantype i = SCAN_NULL; i < SCAN_ALL; i++)
@ -25,16 +26,12 @@ static void print_port_state(const struct response *response, e_scantype type)
printf("\n");
}
void print_host_results(const char *ip_addr, const struct response *responses,
const struct option_lst *options, double scan_time)
void print_host_results(const struct scan *general, double scan_time)
{
printf("Scan took %lf secs\n", scan_time);
printf("IP address: %s\n", ip_addr);
printf("IP address: %s\n", general->dest_addr);
printf("Open ports:\n");
uint16_t port_start = 1, port_end = 1024;
parse_ports(get_option_arg(options, FL_PORTS), &port_start, &port_end);
e_scantype type = parse_type(get_option_arg(options, FL_SCAN));
for (uint16_t i = port_start; i < port_end - port_start; i++) {
print_port_state(&responses[i], type);
for (uint16_t port = general->port_start; port < general->port_end; port++) {
print_port_state(port, general->type, &general->responses[port - general->port_start]);
}
}