OpenVAS Scanner 23.40.3
hosts.h File Reference

hosts.c header. More...

#include "../misc/scanneraux.h"
#include <gvm/base/hosts.h>
Include dependency graph for hosts.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int hosts_init (int)
int hosts_new (char *, kb_t, kb_t)
int hosts_set_pid (char *, pid_t)
int hosts_read (void)
 Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.
void hosts_stop_all (void)
void host_set_time (kb_t, char *, char *)
 Add star_scan and end_scan results to the main kb.
int host_is_currently_scanned (gvm_host_t *)
 Returns 1 if the host is being scanned. 0 otherwise.

Detailed Description

hosts.c header.

Definition in file hosts.h.

Function Documentation

◆ host_is_currently_scanned()

int host_is_currently_scanned ( gvm_host_t * host_to_check)

Returns 1 if the host is being scanned. 0 otherwise.

It checks not only the main IP of the host, but also the ips that a dns-lookup returns.

Definition at line 271 of file hosts.c.

272{
273 struct host *h = hosts;
274
275 GSList *list, *tmp;
276 char *vhost = NULL;
277
278 hosts_read ();
279
280 if (h == NULL)
281 return 0;
282
283 vhost = gvm_host_reverse_lookup (host_to_check);
284 if (!vhost)
285 return 0;
286
287 list = tmp = gvm_resolve_list (vhost);
288 g_free (vhost);
289 while (tmp)
290 {
291 h = hosts;
292 char buffer[INET6_ADDRSTRLEN];
293 addr6_to_str (tmp->data, buffer);
294
295 while (h != NULL)
296 {
297 if (!strcasecmp (h->name, buffer))
298 {
299 g_slist_free_full (list, g_free);
300 return 1;
301 }
302 h = h->next;
303 }
304 tmp = tmp->next;
305 }
306
307 g_slist_free_full (list, g_free);
308 return 0;
309}
static struct host * hosts
Definition hosts.c:49
int hosts_read(void)
Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.
Definition hosts.c:253
Host information, implemented as doubly linked list.
Definition hosts.c:37
struct host * next
Definition hosts.c:43
char * name
Definition hosts.c:38

References hosts, hosts_read(), host::name, and host::next.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ host_set_time()

void host_set_time ( kb_t kb,
char * ip,
char * type )

Add star_scan and end_scan results to the main kb.

Parameters
[in]kbMain KB where results are stored.
[in]ipList of vhosts to add new vhosts to.
[in]typeIf it is start or end message.

Definition at line 64 of file hosts.c.

65{
66 char *timestr;
67 char log_msg[1024];
68 time_t t;
69 int len;
70
71 t = time (NULL);
72 char ts[26];
73 char *ts_ptr = ts;
74 ctime_r (&t, ts_ptr);
75 timestr = g_strdup (ts_ptr);
76 len = strlen (timestr);
77 if (timestr[len - 1] == '\n')
78 timestr[len - 1] = '\0';
79
80 snprintf (log_msg, sizeof (log_msg), "%s|||%s||||||||| |||%s", type, ip,
81 timestr);
82 g_free (timestr);
83
84 kb_item_push_str_with_main_kb_check (kb, "internal/results", log_msg);
85}
uint8_t len
int kb_item_push_str_with_main_kb_check(kb_t kb, const char *name, const char *value)
Check if the current kb corresponds to the original scanid, if it matches it kb_item_push_str....
Definition plugutils.c:533

References host::ip, kb_item_push_str_with_main_kb_check(), and len.

Referenced by attack_host().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_init()

int hosts_init ( int max_hosts)

Definition at line 144 of file hosts.c.

145{
146 g_max_hosts = max_hosts;
147 return 0;
148}
static int g_max_hosts
Definition hosts.c:50

References g_max_hosts.

Referenced by attack_network().

Here is the caller graph for this function:

◆ hosts_new()

int hosts_new ( char * name,
kb_t kb,
kb_t main_kb )

Definition at line 151 of file hosts.c.

152{
153 struct host *h;
154
155 while (hosts_num () >= g_max_hosts)
156 {
157 if (hosts_read () < 0)
158 return -1;
159 }
161 return 0;
162
163 h = g_malloc0 (sizeof (struct host));
164 h->name = g_strdup (name);
165 h->pid = 0;
166 h->host_kb = kb;
167 h->results_kb = main_kb;
168 if (hosts != NULL)
169 hosts->prev = h;
170 h->next = hosts;
171 h->prev = NULL;
172 hosts = h;
173 return 0;
174}
int global_scan_stop
Definition attack.c:261
static int hosts_num(void)
Returns the number of entries in the global hosts list.
Definition hosts.c:116
kb_t main_kb
Definition kb_cache.c:15
const char * name
Definition nasl_init.c:440
struct host * prev
Definition hosts.c:44
kb_t host_kb
Definition hosts.c:41
pid_t pid
Definition hosts.c:40
kb_t results_kb
Definition hosts.c:42

References g_max_hosts, global_scan_stop, host::host_kb, hosts, hosts_num(), hosts_read(), main_kb, host::name, name, host::next, host::pid, host::prev, and host::results_kb.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_read()

int hosts_read ( void )

Returns -1 if client asked to stop all tests or connection was lost or error. 0 otherwise.

Definition at line 253 of file hosts.c.

254{
255 if (hosts == NULL)
256 return -1;
257
259 usleep (500000);
260
261 return 0;
262}
static void hosts_read_data(void)
Definition hosts.c:218

References hosts, and hosts_read_data().

Referenced by attack_network(), host_is_currently_scanned(), and hosts_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_set_pid()

int hosts_set_pid ( char * name,
pid_t pid )

Definition at line 177 of file hosts.c.

178{
179 struct host *h = hosts_get (name);
180 if (h == NULL)
181 {
182 g_debug ("host_set_pid() failed!\n");
183 return -1;
184 }
185
186 h->pid = pid;
187 return 0;
188}
static struct host * hosts_get(char *name)
Retrieves a host specified by its name from the global host list.
Definition hosts.c:131
static pid_t pid

References hosts_get(), name, host::pid, and pid.

Referenced by attack_network().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hosts_stop_all()

void hosts_stop_all ( void )

Definition at line 203 of file hosts.c.

204{
205 struct host *host = hosts;
206
208 while (host)
209 {
211 host = host->next;
212 }
213}
static int hosts_stop_host(struct host *h)
Definition hosts.c:192

References global_scan_stop, hosts, hosts_stop_host(), and host::next.

Referenced by scan_stop_cleanup().

Here is the call graph for this function:
Here is the caller graph for this function: