Skip to content

Commit 9884b11

Browse files
committed
Update default timeout and scan values
The changes update default parameter values in constants.h and centralize them there instead of having hard-coded values scattered across the codebase. I'd write: Update default values and fix memory leaks This commit: - Centralizes default parameter values in constants.h - Fixes memory leaks in scan methods and JSON handling - Updates ping loop retry logic - Improves thread index access in scanning module - Adds more future features to docs
1 parent 3883d19 commit 9884b11

File tree

14 files changed

+57
-73
lines changed

14 files changed

+57
-73
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ol>
1919

2020
<h1 id="how-to-contribute">How to find someting to contribute</h1>
21-
<p>Head over to the <a href="https://github.com/Alfredsson418/hawkeyes/issues">Issues</a> tab and find something you can help with!
21+
<p>Head over to the <a href="https://github.com/Alfredsson418/hawkeyes/issues">Issues</a> tab or <a href="docs/FUTURE_IDEAS.md">FUTURE_IDEAS.md</a> and find something you can help with!
2222
You could also create your own Issues with the given templates. <b>Just make sure that you get the go-ahead on the issue before creating your pull request</b>.</p>
2323

2424
<h1>Coding format</h1>

data/version/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Add this file to ./git/hooks/ to auto increase the version number pre commit
44

5+
6+
echo "Updating patch"
57
./data/version/increase.sh 0 0 1
68

79
# Because he files change, we need to add it again before the commit

docs/FUTURE_IDEAS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Future implementetion ideas
22
- Mobile network support
3-
- Target enumeration
3+
- Target enumeration (Network discovery)
44
- Hostname
55
- MAC Adress
6+
- etc
7+
- Test cases
8+
- Install script
9+
- Convert port files to json format

docs/USAGE.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,6 @@ This works mostly on older firewalls because modern firewalls will not responde
147147
</table>
148148

149149

150-
<h2>Timeout</h2>
151-
<table>
152-
<tr>
153-
<th>Short Option</th>
154-
<th>Long Option</th>
155-
<th>Description</th>
156-
<th>Default Value</th>
157-
<th>Possible values</th>
158-
</tr>
159-
<tr>
160-
<td>-w TIME</td>
161-
<td>--timeout TIME</td>
162-
<td>This is the time (in SECONDS) before a port is declared as closed.</td>
163-
<td>3 seconds</td>
164-
<td>Any positive integer between 0 and MAX_INT</td>
165-
</tr>
166-
</table>
167-
168-
169150
<h2>Workers</h2>
170151
<table>
171152
<tr>

include/constans.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#pragma once
22

3+
/*
4+
================================
5+
DEFAULT PARAMETER VALUES
6+
================================
7+
*/
8+
9+
#define DEFAULT_TIMEOUT 3
10+
#define DEFAULT_NO_PING false
11+
#define DEFAULT_THREAD_WORKERS 3
12+
#define DEFAULT_PORT_INTERVAL "1-1000"
13+
14+
/*
15+
================================
16+
DEFAULT PROGRAM VALUES
17+
================================
18+
*/
19+
320
#define RESULT_PORT_LEN 10 // 65535 + /tcp or /udp or other
421
#define RESULT_SERVICE_LEN PORT_SERVICE_LEN
522
#define RESULT_METHOD_LEN 20

include/other/ip/range.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/hawkeyes.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ int main(int argc, char *argv[]) {
2323
memset(arguments.interface, '\0', INTERFACE_LEN);
2424
memset(arguments.ports_format, '\0', PORTS_FORMAT_LEN);
2525
memset(&arguments.scan_info, 0, sizeof(scan_func_t));
26-
arguments.timeout = 3;
27-
arguments.no_ping = false;
28-
arguments.thread_workers = 3;
26+
arguments.timeout = DEFAULT_TIMEOUT;
27+
arguments.no_ping = DEFAULT_NO_PING;
28+
arguments.thread_workers = DEFAULT_THREAD_WORKERS;
29+
strncpy(arguments.ports_format, DEFAULT_PORT_INTERVAL, PORTS_FORMAT_LEN);
2930

3031
unsigned short closed_ports = 0;
3132
unsigned short error_ports = 0;
@@ -104,17 +105,11 @@ int main(int argc, char *argv[]) {
104105

105106
VERBOSE_MESSAGE("Network interface: %s\n", interface.name);
106107

107-
if (arguments.ports_format[0] == '\0') {
108-
strncpy(arguments.ports_format, "1-1000", INTERFACE_LEN);
109-
VERBOSE_MESSAGE("Port range was not set, using default %s \n",
110-
arguments.ports_format);
111-
}
112-
113108
/*
114109
===========================================================
115110
*/
116111
unsigned short *ports;
117-
unsigned int port_len = parse_ports(arguments.ports_format, &(ports));
112+
unsigned int port_len = parse_ports(arguments.ports_format, &ports);
118113
if (port_len == 0) {
119114
ERR_PRINT("Failed to parse ports\n");
120115
return -1;

src/other/ip/range.c

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/other/network_interface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "../../include/other/network_interface.h"
22

33
int _ping(struct ifaddrs *ifa, struct sockaddr_storage ip_addr) {
4+
int tries = 2;
45
int respone;
56
VERBOSE_MESSAGE("PING REQUEST: Trying on '%s': ", ifa->ifa_name);
6-
for (int i = 1; i <= 2; i++) {
7+
for (int i = 0; i < tries; i++) {
78
respone = ping(ip_addr, ifa->ifa_name);
89
if (respone > 0) {
910
VERBOSE_MESSAGE("SUCCESSFULL\n");

src/other/next_best_packet.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ net_packet *next_best_packet(next_best_args *in_args) {
9898
// Start scanning for matching packages
9999
pcap_dispatch(package_handle, 1, (pcap_handler)loop_back,
100100
(unsigned char *)return_arg);
101-
pcap_close(package_handle);
102101

103102
pthread_cancel(thread_id);
104103
// This it to make sure the "sleep" thread exists as expected
105104
// pthread_join(thread_id, NULL);
106105

106+
pcap_freecode(&pcap_filter);
107+
pcap_close(package_handle);
108+
107109
return return_arg;
108110
}

0 commit comments

Comments
 (0)