OpenVAS Scanner 23.40.3
nasl_host.c File Reference

Remote host helper functions. More...

#include "nasl_host.h"
#include "../misc/ipc_openvas.h"
#include "../misc/network.h"
#include "../misc/pcap_openvas.h"
#include "../misc/plugutils.h"
#include "base/hosts.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <arpa/inet.h>
#include <gvm/base/networking.h>
#include <gvm/util/kb.h>
#include <limits.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
Include dependency graph for nasl_host.c:

Go to the source code of this file.

Macros

#define G_LOG_DOMAIN   "sd nasl"
 GLib log domain.

Functions

tree_cellget_hostnames (lex_ctxt *lexic)
tree_cellget_hostname (lex_ctxt *lexic)
tree_cellget_hostname_source (lex_ctxt *lexic)
tree_celladd_hostname (lex_ctxt *lexic)
tree_cellresolve_hostname_to_multiple_ips (lex_ctxt *lexic)
 Resolve a hostname and return all ip addresses as nasl array.
tree_cellresolve_hostname (lex_ctxt *lexic)
tree_cellget_host_ip (lex_ctxt *lexic)
tree_cellget_host_open_port (lex_ctxt *lexic)
tree_cellhost_reverse_lookup (lex_ctxt *lexic)
 implements ip_reverse_lookup
tree_cellget_port_state (lex_ctxt *lexic)
tree_cellget_udp_port_state (lex_ctxt *lexic)
tree_cellnasl_islocalhost (lex_ctxt *lexic)
tree_cellnasl_islocalnet (lex_ctxt *lexic)
tree_cellnasl_this_host (lex_ctxt *lexic)
tree_cellnasl_this_host_name (lex_ctxt *lexic)
tree_cellget_port_transport (lex_ctxt *lexic)
 Return the encapsulation mode of a port.
tree_cellnasl_same_host (lex_ctxt *lexic)
tree_cellnasl_target_is_ipv6 (lex_ctxt *lexic)

Detailed Description

Remote host helper functions.

This file contains all the functions which deal with the remote host: which ports are open, what is its IP, what is our IP, what transport is on the remote port, and so on...

Definition in file nasl_host.c.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "sd nasl"

GLib log domain.

Definition at line 47 of file nasl_host.c.

Function Documentation

◆ add_hostname()

tree_cell * add_hostname ( lex_ctxt * lexic)

Definition at line 113 of file nasl_host.c.

114{
115 struct ipc_data *hn = NULL;
116 char *lower;
117 const char *json = NULL;
118 char *value = get_str_var_by_name (lexic, "hostname");
119 char *source = get_str_var_by_name (lexic, "source");
120
121 if (!value)
122 {
123 nasl_perror (lexic, "%s: Empty hostname\n", __func__);
124 return NULL;
125 }
126 if (!source || !*source)
127 source = "NASL";
128 /* Add to current process' vhosts list. */
129 lower = g_ascii_strdown (value, -1);
130 hn = ipc_data_type_from_hostname (source, strlen (source), lower,
131 strlen (lower));
132 json = ipc_data_to_json (hn);
133 ipc_data_destroy (&hn);
134 if (plug_add_host_fqdn (lexic->script_infos, lower, source))
135 goto end_add_hostname;
136
137 // send it to host process to extend vhosts list there
138 if (ipc_send (lexic->script_infos->ipc_context, IPC_MAIN, json, strlen (json))
139 < 0)
140 g_warning ("Unable to send %s to host process", lower);
141
142end_add_hostname:
143 g_free (lower);
144 g_free ((void *) json);
145 return NULL;
146}
int ipc_send(struct ipc_context *context, enum ipc_relation to, const char *msg, size_t len)
sends given msg to the target based on the given context
Definition ipc.c:46
@ IPC_MAIN
Definition ipc.h:18
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
const char * ipc_data_to_json(ipc_data_t *data)
transforms ipc_data to a json string
ipc_data_t * ipc_data_type_from_hostname(const char *source, size_t source_len, const char *hostname, size_t hostname_len)
initializes ipc_data for a hostname data.
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition nasl_debug.c:105
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition nasl_var.c:1118
int plug_add_host_fqdn(struct script_infos *args, const char *hostname, const char *source)
Definition plugutils.c:257
struct ipc_context * ipc_context
Definition scanneraux.h:31
struct script_infos * script_infos

References get_str_var_by_name(), script_infos::ipc_context, ipc_data_destroy(), ipc_data_to_json(), ipc_data_type_from_hostname(), IPC_MAIN, ipc_send(), nasl_perror(), plug_add_host_fqdn(), and struct_lex_ctxt::script_infos.

Here is the call graph for this function:

◆ get_host_ip()

tree_cell * get_host_ip ( lex_ctxt * lexic)

Definition at line 208 of file nasl_host.c.

209{
210 struct script_infos *script_infos = lexic->script_infos;
211 struct in6_addr *ip = plug_get_host_ip (script_infos);
212 tree_cell *retc;
213
214 if (ip == NULL) /* WTF ? */
215 {
216 return FAKE_CELL;
217 }
218
220 retc->x.str_val = addr6_as_str (ip);
221 retc->size = strlen (retc->x.str_val);
222
223 return retc;
224}
tree_cell * alloc_typed_cell(int typ)
Definition nasl_tree.c:25
@ CONST_STR
Definition nasl_tree.h:80
struct TC tree_cell
#define FAKE_CELL
Definition nasl_tree.h:110
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Definition plugutils.c:371
long int size
Definition nasl_tree.h:99
union TC::@332262321161220155002104006201360276211317150140 x
char * str_val
Definition nasl_tree.h:103

References alloc_typed_cell(), CONST_STR, FAKE_CELL, plug_get_host_ip(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ get_host_open_port()

tree_cell * get_host_open_port ( lex_ctxt * lexic)

Definition at line 227 of file nasl_host.c.

228{
229 struct script_infos *script_infos = lexic->script_infos;
230 unsigned int port = plug_get_host_open_port (script_infos);
231 tree_cell *retc;
232
234 retc->x.i_val = port;
235
236 return retc;
237}
@ CONST_INT
Definition nasl_tree.h:79
unsigned int plug_get_host_open_port(struct script_infos *desc)
Definition plugutils.c:1328
long int i_val
Definition nasl_tree.h:104

References alloc_typed_cell(), CONST_INT, TC::i_val, plug_get_host_open_port(), struct_lex_ctxt::script_infos, and TC::x.

Here is the call graph for this function:

◆ get_hostname()

tree_cell * get_hostname ( lex_ctxt * lexic)

Definition at line 79 of file nasl_host.c.

80{
81 struct script_infos *script_infos = lexic->script_infos;
83 tree_cell *retc;
84
85 if (hostname == NULL)
86 return NULL;
87
89 retc->size = strlen (hostname);
90 retc->x.str_val = hostname;
91 return retc;
92}
const char * hostname
char * plug_get_host_fqdn(struct script_infos *args)
Definition plugutils.c:291

References alloc_typed_cell(), CONST_STR, hostname, plug_get_host_fqdn(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ get_hostname_source()

tree_cell * get_hostname_source ( lex_ctxt * lexic)

Definition at line 95 of file nasl_host.c.

96{
97 struct script_infos *script_infos = lexic->script_infos;
98 char *source;
99 tree_cell *retc;
100
102 get_str_var_by_name (lexic, "hostname"));
103 if (!source)
104 return NULL;
105
107 retc->size = strlen (source);
108 retc->x.str_val = source;
109 return retc;
110}
char * plug_get_host_source(struct script_infos *args, const char *hostname)
Definition plugutils.c:343

References alloc_typed_cell(), CONST_STR, get_str_var_by_name(), plug_get_host_source(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ get_hostnames()

tree_cell * get_hostnames ( lex_ctxt * lexic)

Definition at line 49 of file nasl_host.c.

50{
51 struct script_infos *script_infos = lexic->script_infos;
52 tree_cell *retc;
53 int i = 0;
54 nasl_array *arr;
55 GSList *tmp, *hostnames;
56
57 hostnames = tmp = plug_get_host_fqdn_list (script_infos);
58 if (!hostnames)
59 return NULL;
60
62 retc->x.ref_val = arr = g_malloc0 (sizeof (nasl_array));
63 while (tmp)
64 {
66
68 v.v.v_str.s_siz = strlen (tmp->data);
69 v.v.v_str.s_val = tmp->data;
70 add_var_to_list (arr, i++, &v);
71 tmp = tmp->next;
72 }
73
74 g_slist_free_full (hostnames, g_free);
75 return retc;
76}
@ DYN_ARRAY
Definition nasl_tree.h:90
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
Definition nasl_var.c:1245
struct st_a_nasl_var anon_nasl_var
struct st_nasl_array nasl_array
@ VAR2_DATA
Definition nasl_var.h:18
GSList * plug_get_host_fqdn_list(struct script_infos *args)
Definition plugutils.c:325
void * ref_val
Definition nasl_tree.h:105
nasl_string_t v_str
Definition nasl_var.h:47
union st_a_nasl_var::@154137074032032170165360023270032033276061363156 v
unsigned char * s_val
Definition nasl_var.h:26
long int s_siz
Definition nasl_var.h:27

References add_var_to_list(), alloc_typed_cell(), DYN_ARRAY, plug_get_host_fqdn_list(), TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, struct_lex_ctxt::script_infos, st_a_nasl_var::v, st_a_nasl_var::v_str, VAR2_DATA, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function:

◆ get_port_state()

tree_cell * get_port_state ( lex_ctxt * lexic)

Definition at line 292 of file nasl_host.c.

293{
294 int open;
295 struct script_infos *script_infos = lexic->script_infos;
296 tree_cell *retc;
297 long int port;
298
299 port = get_int_var_by_num (lexic, 0, -1);
300
301 if (port < 0 || port > USHRT_MAX)
302 return FAKE_CELL;
303
305 open = host_get_port_state (script_infos, port);
306 retc->x.i_val = open;
307 return retc;
308}
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition nasl_var.c:1094
int host_get_port_state(struct script_infos *plugdata, int portnum)
Definition plugutils.c:193

References alloc_typed_cell(), CONST_INT, FAKE_CELL, get_int_var_by_num(), host_get_port_state(), TC::i_val, struct_lex_ctxt::script_infos, and TC::x.

Here is the call graph for this function:

◆ get_port_transport()

tree_cell * get_port_transport ( lex_ctxt * lexic)

Return the encapsulation mode of a port.

NASL Function: get_port_transport\n

Takes a port number and returns its encapsulation mode (ENCAPS_*) The defined encapsulation modes are:

  • ENCAPS_AUTO Automatic encapsulation detection.
  • ENCAPS_IP No encapsulation
  • ENCAPS_SSLv23 Request compatibility options
  • ENCAPS_SSLv2 SSL version 2
  • ENCAPS_SSLv3 SSL version 3
  • ENCAPS_TLSv1 TLS version 1.0
  • ENCAPS_TLSv11 TLS version 1.1
  • ENCAPS_TLSv12 TLS version 1.2
  • ENCAPS_TLSv13 TLS version 1.3
  • ENCAPS_TLScustom SSL or TLS with custom priorities
NASL Unnamed Parameters:\n
  • An integer with the port number.
NASL Named Parameters:\n

-asstring If not 0 return a human readabale string instead of an integer.

NASL Returns:\n An integer or a string with the encapsulation mode or NULL
on error.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.

Definition at line 456 of file nasl_host.c.

457{
458 struct script_infos *script_infos = lexic->script_infos;
459 tree_cell *retc;
460 long int port = get_int_var_by_num (lexic, 0, -1);
461
462 if (port >= 0 && port <= USHRT_MAX)
463 {
464 int trp = plug_get_port_transport (script_infos, port);
465
467 if (get_int_var_by_name (lexic, "asstring", 0))
468 {
469 const char *s = get_encaps_name (trp);
470 retc->x.str_val = g_strdup (s);
471 retc->size = strlen (s);
472 }
473 else
474 {
475 retc->type = CONST_INT;
476 retc->x.i_val = trp;
477 }
478 return retc;
479 }
480 return NULL;
481}
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition nasl_var.c:1101
const char * get_encaps_name(openvas_encaps_t code)
Definition network.c:1733
int plug_get_port_transport(struct script_infos *args, int port)
Definition plugutils.c:1396
short type
Definition nasl_tree.h:95

References alloc_typed_cell(), CONST_INT, CONST_STR, get_encaps_name(), get_int_var_by_name(), get_int_var_by_num(), TC::i_val, plug_get_port_transport(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, TC::type, and TC::x.

Here is the call graph for this function:

◆ get_udp_port_state()

tree_cell * get_udp_port_state ( lex_ctxt * lexic)

Definition at line 311 of file nasl_host.c.

312{
313 int open;
314 struct script_infos *script_infos = lexic->script_infos;
315 tree_cell *retc;
316 long int port;
317
318 port = get_int_var_by_num (lexic, 0, -1);
319 if (port < 0 || port > USHRT_MAX)
320 return FAKE_CELL;
321
324 retc->x.i_val = open;
325 return retc;
326}
int host_get_port_state_udp(struct script_infos *plugdata, int portnum)
Definition plugutils.c:199

References alloc_typed_cell(), CONST_INT, FAKE_CELL, get_int_var_by_num(), host_get_port_state_udp(), TC::i_val, struct_lex_ctxt::script_infos, and TC::x.

Here is the call graph for this function:

◆ host_reverse_lookup()

tree_cell * host_reverse_lookup ( lex_ctxt * lexic)

implements ip_reverse_lookup

Definition at line 245 of file nasl_host.c.

246{
247 char *t = get_str_var_by_num (lexic, 0);
248 gvm_host_t *target = NULL;
249 tree_cell *retc;
250
251 if (t == NULL)
252 {
254 }
255 else
256 {
257 // we need to duplicate t because plug_get_host_ip_from_str allocates
258 // memory and to have the same behavior for both we simply duplicate the
259 // memory here
260 t = g_strdup (t);
261 }
262 if (t == NULL)
263 {
264 nasl_perror (lexic, "Empty target\n");
265 goto fail;
266 }
267 target = gvm_host_from_str (t);
268 if (target == NULL)
269 {
270 nasl_perror (lexic, "%s: Invalid target\n", t);
271 g_free (t);
272 goto fail;
273 }
274 g_free (t);
275
276 t = gvm_host_reverse_lookup (target);
277 if (t == NULL)
278 {
279 goto fail;
280 }
281
283 retc->x.str_val = t;
284 retc->size = strlen (t);
285
286 return retc;
287fail:
288 return FAKE_CELL;
289}
char * get_str_var_by_num(lex_ctxt *, int)
Definition nasl_var.c:1108
char * plug_get_host_ip_str(struct script_infos *desc)
Definition plugutils.c:377

References alloc_typed_cell(), CONST_STR, FAKE_CELL, get_str_var_by_num(), nasl_perror(), plug_get_host_ip_str(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ nasl_islocalhost()

tree_cell * nasl_islocalhost ( lex_ctxt * lexic)

Definition at line 329 of file nasl_host.c.

330{
331 struct script_infos *script_infos = lexic->script_infos;
332 struct in6_addr *dst = plug_get_host_ip (script_infos);
333 tree_cell *retc;
334
336 retc->x.i_val = v6_islocalhost (dst);
337 return retc;
338}
int v6_islocalhost(struct in6_addr *addr)
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface.
Definition pcap.c:234

References alloc_typed_cell(), CONST_INT, TC::i_val, plug_get_host_ip(), struct_lex_ctxt::script_infos, v6_islocalhost(), and TC::x.

Here is the call graph for this function:

◆ nasl_islocalnet()

tree_cell * nasl_islocalnet ( lex_ctxt * lexic)

Definition at line 341 of file nasl_host.c.

342{
343 struct script_infos *script_infos = lexic->script_infos;
344 struct in6_addr *ip = plug_get_host_ip (script_infos);
345 tree_cell *retc;
346
348 retc->x.i_val = v6_is_local_ip (ip);
349 return retc;
350}
int v6_is_local_ip(struct in6_addr *addr)
Definition pcap.c:115

References alloc_typed_cell(), CONST_INT, TC::i_val, plug_get_host_ip(), struct_lex_ctxt::script_infos, v6_is_local_ip(), and TC::x.

Here is the call graph for this function:

◆ nasl_same_host()

tree_cell * nasl_same_host ( lex_ctxt * lexic)

Definition at line 484 of file nasl_host.c.

485{
486 tree_cell *retc;
487 struct hostent *h;
488 char *hn[2], **names[2];
489 struct in_addr ia, *a[2];
490 int i, j, n[2], names_nb[2], flag;
491 int cmp_hostname = get_int_var_by_name (lexic, "cmp_hostname", 0);
492
493 memset (names_nb, '\0', sizeof (names_nb));
494 memset (names, '\0', sizeof (names));
495 memset (a, '\0', sizeof (a));
496 for (i = 0; i < 2; i++)
497 {
498 hn[i] = get_str_var_by_num (lexic, i);
499 if (hn[i] == NULL)
500 {
501 nasl_perror (lexic, "same_host needs two parameters!\n");
502 return NULL;
503 }
504 if (strlen (hn[i]) >= 256)
505 {
506 nasl_perror (lexic, "same_host(): Too long hostname !\n");
507 return NULL;
508 }
509 }
510 for (i = 0; i < 2; i++)
511 {
512 if (!inet_aton (hn[i], &ia)) /* Not an IP address */
513 {
514 h = gethostbyname (hn[i]);
515 if (h == NULL)
516 {
517 nasl_perror (lexic, "same_host: %s does not resolve\n", hn[i]);
518 n[i] = 0;
519 if (cmp_hostname)
520 {
521 names_nb[i] = 1;
522 names[i] = g_malloc0 (sizeof (char *));
523 names[i][0] = g_strdup (hn[i]);
524 }
525 }
526 else
527 {
528 for (names_nb[i] = 0; h->h_aliases[names_nb[i]] != NULL;
529 names_nb[i]++)
530 ;
531 names_nb[i]++;
532 names[i] = g_malloc0 (sizeof (char *) * names_nb[i]);
533 names[i][0] = g_strdup (h->h_name);
534 for (j = 1; j < names_nb[i]; j++)
535 names[i][j] = g_strdup (h->h_aliases[j - 1]);
536
537 /* Here, we should check that h_addrtype == AF_INET */
538 for (n[i] = 0; ((struct in_addr **) h->h_addr_list)[n[i]] != NULL;
539 n[i]++)
540 ;
541 a[i] = g_malloc0 ((gsize) h->h_length * n[i]);
542 for (j = 0; j < n[i]; j++)
543 a[i][j] = *((struct in_addr **) h->h_addr_list)[j];
544 }
545 }
546 else
547 {
548 if (cmp_hostname)
549 h = gethostbyaddr ((const char *) &ia, sizeof (ia), AF_INET);
550 else
551 h = NULL;
552 if (h == NULL)
553 {
554 a[i] = g_malloc0 (sizeof (struct in_addr));
555 memcpy (a[i], &ia, sizeof (struct in_addr));
556 n[i] = 1;
557 }
558 else
559 {
560 for (names_nb[i] = 0; h->h_aliases[names_nb[i]] != NULL;
561 names_nb[i]++)
562 ;
563 names_nb[i]++;
564 names[i] = g_malloc0 (sizeof (char *) * names_nb[i]);
565 names[i][0] = g_strdup (h->h_name);
566 for (j = 1; j < names_nb[i]; j++)
567 names[i][j] = g_strdup (h->h_aliases[j - 1]);
568
569 /* Here, we should check that h_addrtype == AF_INET */
570 for (n[i] = 0; ((struct in_addr **) h->h_addr_list)[n[i]] != NULL;
571 n[i]++)
572 ;
573 a[i] = g_malloc0 ((gsize) h->h_length * n[i]);
574 for (j = 0; j < n[i]; j++)
575 a[i][j] = *((struct in_addr **) h->h_addr_list)[j];
576 }
577 }
578 }
579 flag = 0;
580 for (i = 0; i < n[0] && !flag; i++)
581 for (j = 0; j < n[1] && !flag; j++)
582 if (a[0][i].s_addr == a[1][j].s_addr)
583 {
584 flag = 1;
585 }
586
587 if (cmp_hostname)
588 for (i = 0; i < names_nb[0] && !flag; i++)
589 for (j = 0; j < names_nb[1] && !flag; j++)
590 if (strcmp (names[0][i], names[1][j]) == 0)
591 {
592 flag = 1;
593 }
594
596 retc->x.i_val = flag;
597
598 for (i = 0; i < 2; i++)
599 g_free (a[i]);
600
601 for (i = 0; i < 2; i++)
602 {
603 for (j = 0; j < names_nb[i]; j++)
604 g_free (names[i][j]);
605 g_free (names[i]);
606 }
607
608 return retc;
609}

References alloc_typed_cell(), CONST_INT, get_int_var_by_name(), get_str_var_by_num(), TC::i_val, nasl_perror(), and TC::x.

Here is the call graph for this function:

◆ nasl_target_is_ipv6()

tree_cell * nasl_target_is_ipv6 ( lex_ctxt * lexic)

Definition at line 612 of file nasl_host.c.

613{
614 tree_cell *retc;
615 struct script_infos *script_infos = lexic->script_infos;
616 struct in6_addr *addr;
617
620
621 if (addr == NULL)
622 {
623 nasl_perror (lexic, "address is NULL!\n");
624 return NULL;
625 }
626 if (IN6_IS_ADDR_V4MAPPED (addr) == 1)
627 retc->x.i_val = 0;
628 else
629 retc->x.i_val = 1;
630
631 return retc;
632}

References alloc_typed_cell(), CONST_INT, TC::i_val, nasl_perror(), plug_get_host_ip(), struct_lex_ctxt::script_infos, and TC::x.

Here is the call graph for this function:

◆ nasl_this_host()

tree_cell * nasl_this_host ( lex_ctxt * lexic)

Definition at line 353 of file nasl_host.c.

354{
355 struct script_infos *script_infos = lexic->script_infos;
356 tree_cell *retc;
357 char hostname[255];
358 struct in6_addr *ia = plug_get_host_ip (script_infos);
359 struct in6_addr in6addr;
360 struct in6_addr src6;
361
363
364 if (gvm_source_iface_is_set ())
365 {
366 struct in6_addr addr;
367
368 /* Use source_iface's IP address when available. */
369 if (IN6_IS_ADDR_V4MAPPED (ia))
370 gvm_source_addr_as_addr6 (&addr);
371 else
372 gvm_source_addr6 (&addr);
373 retc->x.str_val = addr6_as_str (&addr);
374 retc->size = strlen (retc->x.str_val);
375 return retc;
376 }
377 else
378 {
379 /* Manually find the source IP that will be used. */
380 int err = 1;
381 if (v6_islocalhost (ia))
382 memcpy (&src6, ia, sizeof (struct in6_addr));
383 else
384 err = v6_getsourceip (&src6, ia);
385
386 if (err && !IN6_ARE_ADDR_EQUAL (&src6, &in6addr_any))
387 {
388 retc->x.str_val = addr6_as_str (&src6);
389 retc->size = strlen (retc->x.str_val);
390
391 return retc;
392 }
393
394 hostname[sizeof (hostname) - 1] = '\0';
395 gethostname (hostname, sizeof (hostname) - 1);
396 if (gvm_resolve_as_addr6 (hostname, &in6addr))
397 {
398 retc->x.str_val = addr6_as_str (&in6addr);
399 retc->size = strlen (retc->x.str_val);
400 }
401 }
402 return retc;
403}
@ CONST_DATA
Definition nasl_tree.h:82
int v6_getsourceip(struct in6_addr *src, struct in6_addr *dst)
Definition pcap.c:487

References alloc_typed_cell(), CONST_DATA, hostname, plug_get_host_ip(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, v6_getsourceip(), v6_islocalhost(), and TC::x.

Here is the call graph for this function:

◆ nasl_this_host_name()

tree_cell * nasl_this_host_name ( lex_ctxt * lexic)

Definition at line 406 of file nasl_host.c.

407{
408 char *hostname;
409 tree_cell *retc;
410
411 (void) lexic;
413
414 hostname = g_malloc0 (256);
415 gethostname (hostname, 255);
416
417 retc->x.str_val = hostname;
418 retc->size = strlen (hostname);
419 return retc;
420}

References alloc_typed_cell(), CONST_DATA, hostname, TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ resolve_hostname()

tree_cell * resolve_hostname ( lex_ctxt * lexic)

Definition at line 186 of file nasl_host.c.

187{
188 struct in6_addr in6addr;
189 char *value = get_str_var_by_name (lexic, "hostname");
190
191 if (!value)
192 {
193 nasl_perror (lexic, "%s: Empty hostname\n", __func__);
194 return NULL;
195 }
196
197 if (!gvm_resolve_as_addr6 (value, &in6addr))
198 {
200 retc->x.str_val = addr6_as_str (&in6addr);
201 retc->size = strlen (retc->x.str_val);
202 return retc;
203 }
204 return NULL;
205}

References alloc_typed_cell(), CONST_STR, get_str_var_by_name(), nasl_perror(), TC::size, TC::str_val, and TC::x.

Here is the call graph for this function:

◆ resolve_hostname_to_multiple_ips()

tree_cell * resolve_hostname_to_multiple_ips ( lex_ctxt * lexic)

Resolve a hostname and return all ip addresses as nasl array.

Definition at line 153 of file nasl_host.c.

154{
155 GSList *list = NULL;
156 char *value = get_str_var_by_name (lexic, "hostname");
157 tree_cell *retc;
158 nasl_array *arr;
159 int i = 0;
160
161 if (!value)
162 {
163 nasl_perror (lexic, "%s: Empty hostname\n", __func__);
164 return NULL;
165 }
166
167 list = gvm_resolve_list (value);
168
170 retc->x.ref_val = arr = g_malloc0 (sizeof (nasl_array));
171 while (list)
172 {
173 anon_nasl_var var_aux;
174
175 var_aux.var_type = VAR2_DATA;
176 var_aux.v.v_str.s_siz = strlen (addr6_as_str (list->data));
177 var_aux.v.v_str.s_val = (unsigned char *) addr6_as_str (list->data);
178 add_var_to_list (arr, i++, &var_aux);
179 list = list->next;
180 }
181 g_slist_free_full (list, g_free);
182 return retc;
183}
struct list * next

References add_var_to_list(), alloc_typed_cell(), DYN_ARRAY, get_str_var_by_name(), nasl_perror(), list::next, TC::ref_val, st_nasl_string::s_siz, st_nasl_string::s_val, st_a_nasl_var::v, st_a_nasl_var::v_str, VAR2_DATA, st_a_nasl_var::var_type, and TC::x.

Here is the call graph for this function: