OpenVAS Libraries  9.0.3
nasl_host.h File Reference
#include "nasl_lex_ctxt.h"
#include "nasl_tree.h"
Include dependency graph for nasl_host.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellget_hostname (lex_ctxt *)
 
tree_cellget_host_ip (lex_ctxt *)
 
tree_cellget_host_open_port (lex_ctxt *)
 
tree_cellget_port_state (lex_ctxt *)
 
tree_cellget_udp_port_state (lex_ctxt *)
 
tree_cellnasl_islocalhost (lex_ctxt *)
 
tree_cellnasl_islocalnet (lex_ctxt *)
 
tree_cellnasl_this_host (lex_ctxt *)
 
tree_cellnasl_this_host_name (lex_ctxt *)
 
tree_cellget_port_transport (lex_ctxt *)
 Return the encapsulation mode of a port. More...
 
tree_cellnasl_same_host (lex_ctxt *)
 
tree_cellnasl_target_is_ipv6 (lex_ctxt *lexic)
 

Function Documentation

◆ get_host_ip()

tree_cell* get_host_ip ( lex_ctxt )

Definition at line 69 of file nasl_host.c.

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

70 {
71  struct arglist *script_infos = lexic->script_infos;
72  struct in6_addr *ip = plug_get_host_ip (script_infos);
73  tree_cell *retc;
74 
75  if (ip == NULL) /* WTF ? */
76  {
77  return FAKE_CELL;
78  }
79 
80  retc = alloc_tree_cell (0, NULL);
81  retc->type = CONST_STR;
82  retc->x.str_val = addr6_as_str (ip);
83  retc->size = strlen (retc->x.str_val);
84 
85  return retc;
86 }
#define FAKE_CELL
Definition: nasl_tree.h:120
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
char * addr6_as_str(const struct in6_addr *addr6)
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ get_host_open_port()

tree_cell* get_host_open_port ( lex_ctxt )

Definition at line 90 of file nasl_host.c.

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

91 {
92  struct arglist *script_infos = lexic->script_infos;
93  unsigned int port = plug_get_host_open_port (script_infos);
94  tree_cell *retc;
95 
96  retc = alloc_tree_cell (0, NULL);
97  retc->type = CONST_INT;
98  retc->x.i_val = port;
99 
100  return retc;
101 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
unsigned int plug_get_host_open_port(struct arglist *desc)
Definition: plugutils.c:917
Here is the call graph for this function:

◆ get_hostname()

tree_cell* get_hostname ( lex_ctxt )

Definition at line 51 of file nasl_host.c.

References alloc_tree_cell(), CONST_STR, plug_get_host_fqdn(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, TC::type, and TC::x.

52 {
53  struct arglist *script_infos = lexic->script_infos;
54  char *hostname = plug_get_host_fqdn (script_infos);
55  tree_cell *retc;
56 
57  if (hostname == NULL)
58  return NULL;
59 
60  retc = alloc_tree_cell (0, NULL);
61  retc->type = CONST_STR;
62  retc->size = strlen (hostname);
63  retc->x.str_val = hostname;
64  return retc;
65 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
char * plug_get_host_fqdn(struct arglist *desc)
Definition: plugutils.c:200
union TC::@7 x
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ get_port_state()

tree_cell* get_port_state ( lex_ctxt )

Definition at line 105 of file nasl_host.c.

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

106 {
107  int open;
108  struct arglist *script_infos = lexic->script_infos;
109  tree_cell *retc;
110  int port;
111 
112  port = get_int_var_by_num (lexic, 0, -1);
113  if (port < 0)
114  return FAKE_CELL;
115 
116  retc = alloc_tree_cell (0, NULL);
117  retc->type = CONST_INT;
118  open = host_get_port_state (script_infos, port);
119  retc->x.i_val = open;
120  return retc;
121 }
#define FAKE_CELL
Definition: nasl_tree.h:120
short type
Definition: nasl_tree.h:107
int host_get_port_state(struct arglist *plugdata, int portnum)
Definition: plugutils.c:177
union TC::@7 x
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
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

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_TLScustom SSL or TLS with custom priorities
NASL Unnamed Parameters:
  • An integer with the port number.
NASL Named Parameters:

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

NASL Returns: 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 277 of file nasl_host.c.

References alloc_tree_cell(), CONST_INT, CONST_STR, get_encaps_name(), get_int_local_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.

278 {
279  struct arglist *script_infos = lexic->script_infos;
280  tree_cell *retc;
281  int port = get_int_var_by_num (lexic, 0, -1);
282 
283  if (port >= 0)
284  {
285  int trp = plug_get_port_transport (script_infos, port);
286 
287  retc = alloc_tree_cell (0, NULL);
288  if (get_int_local_var_by_name (lexic, "asstring", 0))
289  {
290  const char *s = get_encaps_name (trp);
291  retc->type = CONST_STR;
292  retc->x.str_val = g_strdup (s);
293  retc->size = strlen (s);
294  }
295  else
296  {
297  retc->type = CONST_INT;
298  retc->x.i_val = trp;
299  }
300  return retc;
301  }
302  return NULL;
303 }
const char * get_encaps_name(openvas_encaps_t code)
Definition: network.c:1729
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
int plug_get_port_transport(struct arglist *args, int port)
Definition: plugutils.c:990
int size
Definition: nasl_tree.h:110
Here is the call graph for this function:

◆ get_udp_port_state()

tree_cell* get_udp_port_state ( lex_ctxt )

Definition at line 124 of file nasl_host.c.

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

125 {
126  int open;
127  struct arglist *script_infos = lexic->script_infos;
128  tree_cell *retc;
129  int port;
130 
131  port = get_int_var_by_num (lexic, 0, -1);
132  if (port < 0)
133  return FAKE_CELL;
134 
135  retc = alloc_tree_cell (0, NULL);
136  retc->type = CONST_INT;
137  open = host_get_port_state_udp (script_infos, port);
138  retc->x.i_val = open;
139  return retc;
140 }
#define FAKE_CELL
Definition: nasl_tree.h:120
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1226
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int host_get_port_state_udp(struct arglist *plugdata, int portnum)
Definition: plugutils.c:183
Here is the call graph for this function:

◆ nasl_islocalhost()

tree_cell* nasl_islocalhost ( lex_ctxt )

Definition at line 144 of file nasl_host.c.

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

145 {
146  struct arglist *script_infos = lexic->script_infos;
147  struct in6_addr *dst = plug_get_host_ip (script_infos);
148  tree_cell *retc;
149 
150  retc = alloc_tree_cell (0, NULL);
151  retc->type = CONST_INT;
152  retc->x.i_val = v6_islocalhost (dst);
153  return retc;
154 }
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:378
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_islocalnet()

tree_cell* nasl_islocalnet ( lex_ctxt )

Definition at line 158 of file nasl_host.c.

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

159 {
160  struct arglist *script_infos = lexic->script_infos;
161  struct in6_addr *ip = plug_get_host_ip (script_infos);
162  tree_cell *retc;
163 
164  retc = alloc_tree_cell (0, NULL);
165  retc->type = CONST_INT;
166  retc->x.i_val = v6_is_local_ip (ip);
167  return retc;
168 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
int v6_is_local_ip(struct in6_addr *addr)
Definition: pcap.c:106
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
Here is the call graph for this function:

◆ nasl_same_host()

tree_cell* nasl_same_host ( lex_ctxt )

Definition at line 307 of file nasl_host.c.

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

308 {
309  tree_cell *retc;
310  struct hostent *h;
311  char *hn[2], **names[2];
312  struct in_addr ia, *a[2];
313  int i, j, n[2], names_nb[2], flag;
314  int cmp_hostname = get_int_local_var_by_name (lexic, "cmp_hostname", 0);
315 
316  for (i = 0; i < 2; i++)
317  {
318  hn[i] = get_str_var_by_num (lexic, i);
319  if (hn[i] == NULL)
320  {
321  nasl_perror (lexic, "same_host needs two parameters!\n");
322  return NULL;
323  }
324  if (strlen (hn[i]) >= 256)
325  {
326  nasl_perror (lexic, "same_host(): Too long hostname !\n");
327  return NULL;
328  }
329  }
330  for (i = 0; i < 2; i++)
331  {
332  if (!inet_aton (hn[i], &ia)) /* Not an IP address */
333  {
334  h = gethostbyname (hn[i]);
335  if (h == NULL)
336  {
337  nasl_perror (lexic, "same_host: %s does not resolve\n", hn[i]);
338  n[i] = 0;
339  if (cmp_hostname)
340  {
341  names_nb[i] = 1;
342  names[i] = g_malloc0 (sizeof (char *));
343  names[i][0] = g_strdup (hn[i]);
344  }
345  }
346  else
347  {
348  for (names_nb[i] = 0; h->h_aliases[names_nb[i]] != NULL;
349  names_nb[i]++)
350  ;
351  names_nb[i]++;
352  names[i] = g_malloc0 (sizeof (char *) * names_nb[i]);
353  names[i][0] = g_strdup (h->h_name);
354  for (j = 1; j < names_nb[i]; j++)
355  names[i][j] = g_strdup (h->h_aliases[j - 1]);
356 
357  /* Here, we should check that h_addrtype == AF_INET */
358  for (n[i] = 0; ((struct in_addr **) h->h_addr_list)[n[i]] != NULL;
359  n[i]++)
360  ;
361  a[i] = g_malloc0 (h->h_length * n[i]);
362  for (j = 0; j < n[i]; j++)
363  a[i][j] = *((struct in_addr **) h->h_addr_list)[j];
364  }
365  }
366  else
367  {
368  if (cmp_hostname)
369  h = gethostbyaddr ((const char *) &ia, sizeof (ia), AF_INET);
370  else
371  h = NULL;
372  if (h == NULL)
373  {
374  a[i] = g_malloc0 (sizeof (struct in_addr));
375  memcpy (a[i], &ia, sizeof (struct in_addr));
376  n[i] = 1;
377  }
378  else
379  {
380  for (names_nb[i] = 0; h->h_aliases[names_nb[i]] != NULL;
381  names_nb[i]++)
382  ;
383  names_nb[i]++;
384  names[i] = g_malloc0 (sizeof (char *) * names_nb[i]);
385  names[i][0] = g_strdup (h->h_name);
386  for (j = 1; j < names_nb[i]; j++)
387  names[i][j] = g_strdup (h->h_aliases[j - 1]);
388 
389  /* Here, we should check that h_addrtype == AF_INET */
390  for (n[i] = 0; ((struct in_addr **) h->h_addr_list)[n[i]] != NULL;
391  n[i]++)
392  ;
393  a[i] = g_malloc0 (h->h_length * n[i]);
394  for (j = 0; j < n[i]; j++)
395  a[i][j] = *((struct in_addr **) h->h_addr_list)[j];
396  }
397  }
398  }
399  flag = 0;
400  for (i = 0; i < n[0] && !flag; i++)
401  for (j = 0; j < n[1] && !flag; j++)
402  if (a[0][i].s_addr == a[1][j].s_addr)
403  {
404  flag = 1;
405  }
406 
407  if (cmp_hostname)
408  for (i = 0; i < names_nb[0] && !flag; i++)
409  for (j = 0; j < names_nb[1] && !flag; j++)
410  if (strcmp (names[0][i], names[1][j]) == 0)
411  {
412  flag = 1;
413  }
414 
415  retc = alloc_typed_cell (CONST_INT);
416  retc->x.i_val = flag;
417 
418  for (i = 0; i < 2; i++)
419  g_free (a[i]);
420  if (cmp_hostname)
421  {
422  for (i = 0; i < 2; i++)
423  {
424  for (j = 0; j < names_nb[i]; j++)
425  g_free (names[i][j]);
426  g_free (names[i]);
427  }
428  }
429  return retc;
430 }
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1240
union TC::@7 x
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:53
Definition: nasl_tree.h:105
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
char * get_str_var_by_num(lex_ctxt *, int)
Definition: nasl_var.c:1248
long int i_val
Definition: nasl_tree.h:114
Here is the call graph for this function:

◆ nasl_target_is_ipv6()

tree_cell* nasl_target_is_ipv6 ( lex_ctxt lexic)

Definition at line 433 of file nasl_host.c.

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

434 {
435  tree_cell *retc;
436  struct arglist *script_infos = lexic->script_infos;
437  struct in6_addr *addr;
438 
439  addr = plug_get_host_ip (script_infos);
440  retc = alloc_tree_cell (0, NULL);
441  retc->type = CONST_INT;
442 
443  if (addr == NULL)
444  {
445  nasl_perror (lexic, "address is NULL!\n");
446  return NULL;
447  }
448  if (IN6_IS_ADDR_V4MAPPED (addr) == 1)
449  retc->x.i_val = 0;
450  else
451  retc->x.i_val = 1;
452 
453  return retc;
454 }
short type
Definition: nasl_tree.h:107
union TC::@7 x
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:94
long int i_val
Definition: nasl_tree.h:114
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
struct arglist * script_infos
Definition: nasl_lex_ctxt.h:39
Here is the call graph for this function:

◆ nasl_this_host()

tree_cell* nasl_this_host ( lex_ctxt )

Definition at line 172 of file nasl_host.c.

References addr6_as_str(), alloc_tree_cell(), CONST_DATA, err, openvas_resolve_as_addr6(), openvas_source_addr6(), openvas_source_addr_as_addr6(), openvas_source_iface_is_set(), plug_get_host_ip(), struct_lex_ctxt::script_infos, v6_getsourceip(), and v6_islocalhost().

173 {
174  struct arglist *script_infos = lexic->script_infos;
175  tree_cell *retc;
176  char hostname[255];
177  struct in6_addr *ia = plug_get_host_ip (script_infos);
178  struct in6_addr in6addr;
179  struct in6_addr src6;
180 
181  retc = alloc_tree_cell (0, NULL);
182  retc->type = CONST_DATA;
183 
185  {
186  struct in6_addr addr;
187 
188  /* Use source_iface's IP address when available. */
189  if (IN6_IS_ADDR_V4MAPPED (ia))
191  else
192  openvas_source_addr6 (&addr);
193  retc->x.str_val = addr6_as_str (&addr);
194  retc->size = strlen (retc->x.str_val);
195  return retc;
196  }
197  else
198  {
199  /* Manually find the source IP that will be used. */
200  int err = 1;
201  if (v6_islocalhost (ia))
202  memcpy (&src6, ia, sizeof (struct in6_addr));
203  else
204  err = v6_getsourceip (&src6, ia);
205 
206  if (err && !IN6_ARE_ADDR_EQUAL (&src6, &in6addr_any))
207  {
208  retc->x.str_val = addr6_as_str (&src6);
209  retc->size = strlen (retc->x.str_val);
210 
211  return retc;
212  }
213 
214  hostname[sizeof (hostname) - 1] = '\0';
215  gethostname (hostname, sizeof (hostname) - 1);
216  if (openvas_resolve_as_addr6 (hostname, &in6addr))
217  {
218  retc->x.str_val = addr6_as_str (&in6addr);
219  retc->size = strlen (retc->x.str_val);
220  }
221  }
222  return retc;
223 }
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:378
#define err(x)
void openvas_source_addr6(void *addr6)
Gives the source IPv6 address.
int v6_getsourceip(struct in6_addr *src, struct in6_addr *dst)
Definition: pcap.c:692
char * addr6_as_str(const struct in6_addr *addr6)
Definition: nasl_tree.h:105
struct in6_addr * plug_get_host_ip(struct arglist *desc)
Definition: plugutils.c:216
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int openvas_resolve_as_addr6(const char *name, struct in6_addr *ip6)
Resolves a hostname to an IPv4-mapped IPv6 or IPv6 address.
void openvas_source_addr_as_addr6(struct in6_addr *addr6)
Gives the source IPv4 mapped as an IPv6 address. eg. 192.168.20.10 would map to ::ffff:192.168.20.10.
int openvas_source_iface_is_set(void)
Here is the call graph for this function:

◆ nasl_this_host_name()

tree_cell* nasl_this_host_name ( lex_ctxt )

Definition at line 227 of file nasl_host.c.

References alloc_tree_cell(), CONST_DATA, TC::size, TC::str_val, TC::type, and TC::x.

228 {
229  char *hostname;
230  tree_cell *retc;
231 
232  retc = alloc_tree_cell (0, NULL);
233  retc->type = CONST_DATA;
234 
235  hostname = g_malloc0 (256);
236  gethostname (hostname, 255);
237 
238  retc->x.str_val = hostname;
239  retc->size = strlen (hostname);
240  return retc;
241 }
short type
Definition: nasl_tree.h:107
char * str_val
Definition: nasl_tree.h:113
union TC::@7 x
Definition: nasl_tree.h:105
tree_cell * alloc_tree_cell(int lnb, char *s)
Definition: nasl_tree.c:37
int size
Definition: nasl_tree.h:110
Here is the call graph for this function: