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)