31 #include "../misc/network.h" 32 #include "../misc/pcap_openvas.h" 33 #include "../misc/plugutils.h" 41 #include <arpa/inet.h> 42 #include <gvm/base/networking.h> 43 #include <gvm/util/kb.h> 45 #include <netinet/in.h> 56 GSList *tmp, *hostnames;
75 g_slist_free_full (hostnames, g_free);
108 retc->
size = strlen (source);
117 char buffer[4096], *lower;
123 nasl_perror (lexic,
"%s: Empty hostname\n", __FUNCTION__);
126 if (!source || !*source)
130 lower = g_ascii_strdown (value, -1);
132 goto end_add_hostname;
136 snprintf (buffer,
sizeof (buffer),
"internal/source/%s", lower);
138 host_pid = kb_item_get_int (lexic->
script_infos->
key,
"internal/hostpid");
140 kill (host_pid, SIGUSR2);
150 struct in6_addr in6addr;
155 nasl_perror (lexic,
"%s: Empty hostname\n", __FUNCTION__);
159 if (!gvm_resolve_as_addr6 (value, &in6addr))
162 retc->
x.
str_val = addr6_as_str (&in6addr);
182 retc->
x.
str_val = addr6_as_str (ip);
268 struct in6_addr in6addr;
269 struct in6_addr src6;
273 if (gvm_source_iface_is_set ())
275 struct in6_addr addr;
278 if (IN6_IS_ADDR_V4MAPPED (ia))
279 gvm_source_addr_as_addr6 (&addr);
281 gvm_source_addr6 (&addr);
282 retc->x.str_val = addr6_as_str (&addr);
283 retc->size = strlen (retc->x.str_val);
291 memcpy (&src6, ia,
sizeof (
struct in6_addr));
295 if (err && !IN6_ARE_ADDR_EQUAL (&src6, &in6addr_any))
297 retc->x.str_val = addr6_as_str (&src6);
298 retc->size = strlen (retc->x.str_val);
305 if (gvm_resolve_as_addr6 (
hostname, &in6addr))
307 retc->x.str_val = addr6_as_str (&in6addr);
308 retc->size = strlen (retc->x.str_val);
379 retc->
size = strlen (s);
396 char *hn[2], **names[2];
397 struct in_addr ia, *a[2];
398 int i, j, n[2], names_nb[2], flag;
401 memset (names_nb,
'\0',
sizeof (names_nb));
402 memset (names,
'\0',
sizeof (names));
403 memset (a,
'\0',
sizeof (a));
404 for (i = 0; i < 2; i++)
409 nasl_perror (lexic,
"same_host needs two parameters!\n");
412 if (strlen (hn[i]) >= 256)
414 nasl_perror (lexic,
"same_host(): Too long hostname !\n");
418 for (i = 0; i < 2; i++)
420 if (!inet_aton (hn[i], &ia))
422 h = gethostbyname (hn[i]);
425 nasl_perror (lexic,
"same_host: %s does not resolve\n", hn[i]);
430 names[i] = g_malloc0 (
sizeof (
char *));
431 names[i][0] = g_strdup (hn[i]);
436 for (names_nb[i] = 0; h->h_aliases[names_nb[i]] != NULL;
440 names[i] = g_malloc0 (
sizeof (
char *) * names_nb[i]);
441 names[i][0] = g_strdup (h->h_name);
442 for (j = 1; j < names_nb[i]; j++)
443 names[i][j] = g_strdup (h->h_aliases[j - 1]);
446 for (n[i] = 0; ((
struct in_addr **) h->h_addr_list)[n[i]] != NULL;
449 a[i] = g_malloc0 (h->h_length * n[i]);
450 for (j = 0; j < n[i]; j++)
451 a[i][j] = *((
struct in_addr **) h->h_addr_list)[j];
457 h = gethostbyaddr ((
const char *) &ia,
sizeof (ia), AF_INET);
462 a[i] = g_malloc0 (
sizeof (
struct in_addr));
463 memcpy (a[i], &ia,
sizeof (
struct in_addr));
468 for (names_nb[i] = 0; h->h_aliases[names_nb[i]] != NULL;
472 names[i] = g_malloc0 (
sizeof (
char *) * names_nb[i]);
473 names[i][0] = g_strdup (h->h_name);
474 for (j = 1; j < names_nb[i]; j++)
475 names[i][j] = g_strdup (h->h_aliases[j - 1]);
478 for (n[i] = 0; ((
struct in_addr **) h->h_addr_list)[n[i]] != NULL;
481 a[i] = g_malloc0 (h->h_length * n[i]);
482 for (j = 0; j < n[i]; j++)
483 a[i][j] = *((
struct in_addr **) h->h_addr_list)[j];
488 for (i = 0; i < n[0] && !flag; i++)
489 for (j = 0; j < n[1] && !flag; j++)
490 if (a[0][i].s_addr == a[1][j].s_addr)
496 for (i = 0; i < names_nb[0] && !flag; i++)
497 for (j = 0; j < names_nb[1] && !flag; j++)
498 if (strcmp (names[0][i], names[1][j]) == 0)
506 for (i = 0; i < 2; i++)
510 for (i = 0; i < 2; i++)
512 for (j = 0; j < names_nb[i]; j++)
513 g_free (names[i][j]);
525 struct in6_addr *addr;
535 if (IN6_IS_ADDR_V4MAPPED (addr) == 1)
char * plug_get_host_fqdn(struct script_infos *args)
int v6_islocalhost(struct in6_addr *addr)
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface...
int plug_add_host_fqdn(struct script_infos *args, const char *hostname, const char *source)
tree_cell * add_hostname(lex_ctxt *lexic)
const char * get_encaps_name(openvas_encaps_t code)
tree_cell * resolve_hostname(lex_ctxt *lexic)
tree_cell * get_port_state(lex_ctxt *lexic)
int v6_getsourceip(struct in6_addr *src, struct in6_addr *dst)
tree_cell * nasl_target_is_ipv6(lex_ctxt *lexic)
tree_cell * nasl_islocalnet(lex_ctxt *lexic)
GSList * plug_get_host_fqdn_list(struct script_infos *args)
struct script_infos * script_infos
char * plug_get_host_source(struct script_infos *args, const char *hostname)
char * get_str_var_by_name(lex_ctxt *, const char *)
int add_var_to_list(nasl_array *a, int i, const anon_nasl_var *v)
int host_get_port_state_udp(struct script_infos *plugdata, int portnum)
tree_cell * alloc_typed_cell(int typ)
unsigned int plug_get_host_open_port(struct script_infos *desc)
tree_cell * get_hostname(lex_ctxt *lexic)
tree_cell * nasl_this_host(lex_ctxt *lexic)
int plug_get_port_transport(struct script_infos *args, int port)
int host_get_port_state(struct script_infos *plugdata, int portnum)
tree_cell * get_hostname_source(lex_ctxt *lexic)
tree_cell * nasl_islocalhost(lex_ctxt *lexic)
struct in6_addr * plug_get_host_ip(struct script_infos *args)
int v6_is_local_ip(struct in6_addr *addr)
long int get_int_var_by_num(lex_ctxt *, int, int)
void nasl_perror(lex_ctxt *lexic, char *msg,...)
char * get_str_var_by_num(lex_ctxt *, int)
tree_cell * get_host_ip(lex_ctxt *lexic)
long int get_int_var_by_name(lex_ctxt *, const char *, int)
tree_cell * nasl_same_host(lex_ctxt *lexic)
union st_a_nasl_var::@4 v
tree_cell * nasl_this_host_name(lex_ctxt *lexic)
tree_cell * get_host_open_port(lex_ctxt *lexic)
tree_cell * get_hostnames(lex_ctxt *lexic)
tree_cell * get_udp_port_state(lex_ctxt *lexic)
tree_cell * get_port_transport(lex_ctxt *lexic)
Return the encapsulation mode of a port.