fix: timeout changed to 2s + invalid free fix when the socket creation fails

This commit is contained in:
2025-06-16 01:16:16 +02:00
parent ddbaef1826
commit ff89de7fdc
5 changed files with 12 additions and 17 deletions

View File

@ -16,7 +16,7 @@ obj/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(NAME): $(OBJ)
$(LD) $(LDFLAGS) -o $(NAME) $(OBJ)
$(LD) -o $(NAME) $(OBJ) $(LDFLAGS)
clean:
rm -rf obj

View File

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

View File

@ -74,14 +74,10 @@ static void *create_packet(const struct scan *data, size_t packet_size)
iphdr->check = checksum(packet, packet_size);
// this is starnakin stuff
switch ((int)isudp) {
case true:
if (isudp)
create_udp_packet(packet + sizeof(struct iphdr), data);
break;
default:
else
create_tcp_packet(packet + sizeof(struct iphdr), data);
}
return packet;
}
@ -98,12 +94,6 @@ int send_packet(const struct scan *data, int sockfd)
: sizeof(struct tcphdr));
void *packet = create_packet(data, packet_size);
int one = 1;
const int *val = &one;
if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0) {
perror("Error setting IP_HDRINCL");
return -1;
}
sendto(sockfd, packet, packet_size, 0, (struct sockaddr *)&conn_addr,
sizeof(struct sockaddr_in));

View File

@ -64,6 +64,13 @@ int scan(struct scan *data)
return -1;
}
int one = 1;
const int *val = &one;
if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0) {
perror("Error setting IP_HDRINCL");
return -1;
}
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 net, mask;

View File

@ -25,11 +25,9 @@ void *routine(void *p_data)
scan_data.port_end = port;
scan_data.responses =
&thread_data->responses[port - thread_data->port_start];
if (scan(&scan_data)) {
free(p_data);
if (scan(&scan_data))
return NULL;
}
}
return NULL;
}