Greenbone Vulnerability Management Libraries  11.0.1
hosts.h File Reference

Protos and data structures for Hosts collections and single hosts objects. More...

#include <glib.h>
#include <netinet/in.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.

Data Structures

struct  gvm_host
 The structure for a single host object. More...
 
struct  gvm_vhost
 The structure for a single vhost object. More...
 
struct  gvm_hosts
 The structure for Hosts collection. More...
 

Typedefs

typedef struct gvm_host gvm_host_t
 
typedef struct gvm_vhost gvm_vhost_t
 
typedef struct gvm_hosts gvm_hosts_t
 

Enumerations

enum  host_type {
  HOST_TYPE_NAME = 0, HOST_TYPE_IPV4, HOST_TYPE_CIDR_BLOCK, HOST_TYPE_RANGE_SHORT,
  HOST_TYPE_RANGE_LONG, HOST_TYPE_IPV6, HOST_TYPE_CIDR6_BLOCK, HOST_TYPE_RANGE6_LONG,
  HOST_TYPE_RANGE6_SHORT, HOST_TYPE_MAX
}
 

Functions

gvm_hosts_tgvm_hosts_new (const gchar *)
 Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str. More...
 
gvm_hosts_tgvm_hosts_new_with_max (const gchar *, unsigned int)
 Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str. More...
 
gvm_host_tgvm_hosts_next (gvm_hosts_t *)
 Gets the next gvm_host_t from a gvm_hosts_t structure. The state of iteration is kept internally within the gvm_hosts structure. More...
 
void gvm_hosts_free (gvm_hosts_t *)
 Frees memory occupied by an gvm_hosts_t structure. More...
 
void gvm_hosts_shuffle (gvm_hosts_t *)
 Randomizes the order of the hosts objects in the collection. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
void gvm_hosts_reverse (gvm_hosts_t *)
 Reverses the order of the hosts objects in the collection. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
GSList * gvm_hosts_resolve (gvm_hosts_t *)
 Resolves host objects of type name in a hosts collection, replacing hostnames with IPv4 values. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
int gvm_hosts_exclude (gvm_hosts_t *, const char *)
 Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
int gvm_vhosts_exclude (gvm_host_t *, const char *)
 Exclude a list of vhosts from a host's vhosts list. More...
 
int gvm_hosts_exclude_with_max (gvm_hosts_t *, const char *, unsigned int)
 Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
char * gvm_host_reverse_lookup (gvm_host_t *)
 Checks for a host object reverse dns lookup existence. More...
 
int gvm_hosts_reverse_lookup_only (gvm_hosts_t *)
 Removes hosts that don't reverse-lookup from the hosts collection. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
int gvm_hosts_reverse_lookup_unify (gvm_hosts_t *)
 Removes hosts duplicates that reverse-lookup to the same value. Not to be used while iterating over the single hosts as it resets the iterator. More...
 
unsigned int gvm_hosts_count (const gvm_hosts_t *)
 Gets the count of single hosts objects in a hosts collection. More...
 
unsigned int gvm_hosts_removed (const gvm_hosts_t *)
 Gets the count of single values in hosts string that were removed (duplicates / excluded.) More...
 
int gvm_host_in_hosts (const gvm_host_t *, const struct in6_addr *, const gvm_hosts_t *)
 Returns whether a host has an equal host in a hosts collection. eg. 192.168.10.1 has an equal in list created from "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't. More...
 
gchar * gvm_host_type_str (const gvm_host_t *)
 Gets a host's type in printable format. More...
 
enum host_type gvm_host_type (const gvm_host_t *)
 Gets a host object's type. More...
 
gchar * gvm_host_value_str (const gvm_host_t *)
 Gets a host's value in printable format. More...
 
int gvm_host_resolve (const gvm_host_t *, void *, int)
 Resolves a host object's name to an IPv4 or IPv6 address. Host object should be of type HOST_TYPE_NAME. More...
 
int gvm_host_get_addr6 (const gvm_host_t *, struct in6_addr *)
 Gives a host object's value as an IPv6 address. If the host type is hostname, it resolves the IPv4 address then gives an IPv4-mapped IPv6 address (eg. ::ffff:192.168.1.1 .) If the host type is IPv4, it gives an IPv4-mapped IPv6 address. If the host's type is IPv6, it gives the value directly. More...
 
void gvm_host_add_reverse_lookup (gvm_host_t *)
 Add a host's reverse-lookup name to the vhosts list. More...
 
gvm_vhost_tgvm_vhost_new (char *, char *)
 Creates a new gvm_vhost_t object. More...
 
int gvm_get_host_type (const gchar *)
 Determines the host type in a buffer. More...
 

Detailed Description

Protos and data structures for Hosts collections and single hosts objects.

This file contains the protos for hosts.c

Definition in file hosts.h.

Typedef Documentation

◆ gvm_host_t

typedef struct gvm_host gvm_host_t

Definition at line 51 of file hosts.h.

◆ gvm_hosts_t

typedef struct gvm_hosts gvm_hosts_t

Definition at line 53 of file hosts.h.

◆ gvm_vhost_t

typedef struct gvm_vhost gvm_vhost_t

Definition at line 52 of file hosts.h.

Enumeration Type Documentation

◆ host_type

enum host_type
Enumerator
HOST_TYPE_NAME 
HOST_TYPE_IPV4 
HOST_TYPE_CIDR_BLOCK 
HOST_TYPE_RANGE_SHORT 
HOST_TYPE_RANGE_LONG 
HOST_TYPE_IPV6 
HOST_TYPE_CIDR6_BLOCK 
HOST_TYPE_RANGE6_LONG 
HOST_TYPE_RANGE6_SHORT 
HOST_TYPE_MAX 

Definition at line 36 of file hosts.h.

37 {
38  HOST_TYPE_NAME = 0, /* Hostname eg. foo */
39  HOST_TYPE_IPV4, /* eg. 192.168.1.1 */
40  HOST_TYPE_CIDR_BLOCK, /* eg. 192.168.15.0/24 */
41  HOST_TYPE_RANGE_SHORT, /* eg. 192.168.15.10-20 */
42  HOST_TYPE_RANGE_LONG, /* eg. 192.168.15.10-192.168.18.3 */
43  HOST_TYPE_IPV6, /* eg. ::1 */
44  HOST_TYPE_CIDR6_BLOCK, /* eg. ::ffee/120 */
45  HOST_TYPE_RANGE6_LONG, /* eg. ::1:200:7-::1:205:500 */
46  HOST_TYPE_RANGE6_SHORT, /* eg. ::1-fe10 */
47  HOST_TYPE_MAX /* Boundary checking. */
48 };

Function Documentation

◆ gvm_get_host_type()

int gvm_get_host_type ( const gchar *  str_stripped)

Determines the host type in a buffer.

Parameters
[in]str_strippedBuffer that contains host definition, could a be hostname, single IPv4 or IPv6, CIDR-expressed block etc,.
Returns
Host_TYPE_*, -1 if error.

Definition at line 771 of file hosts.c.

772 {
773  /*
774  * We have a single element with no leading or trailing
775  * white spaces. This element could represent different host
776  * definitions: single IPs, host names, CIDR-expressed blocks,
777  * range-expressed networks, IPv6 addresses.
778  */
779 
780  /* Null or empty string. */
781  if (str_stripped == NULL || *str_stripped == '\0')
782  return -1;
783 
784  /* Check for regular single IPv4 address. */
785  if (is_ipv4_address (str_stripped))
786  return HOST_TYPE_IPV4;
787 
788  /* Check for regular single IPv6 address. */
789  if (is_ipv6_address (str_stripped))
790  return HOST_TYPE_IPV6;
791 
792  /* Check for regular IPv4 CIDR-expressed block like "192.168.12.0/24" */
793  if (is_cidr_block (str_stripped))
794  return HOST_TYPE_CIDR_BLOCK;
795 
796  /* Check for short range-expressed networks "192.168.12.5-40" */
797  if (is_short_range_network (str_stripped))
798  return HOST_TYPE_RANGE_SHORT;
799 
800  /* Check for long range-expressed networks "192.168.1.0-192.168.3.44" */
801  if (is_long_range_network (str_stripped))
802  return HOST_TYPE_RANGE_LONG;
803 
804  /* Check for regular IPv6 CIDR-expressed block like "2620:0:2d0:200::7/120" */
805  if (is_cidr6_block (str_stripped))
806  return HOST_TYPE_CIDR6_BLOCK;
807 
808  /* Check for short range-expressed networks "::1-ef12" */
809  if (is_short_range6_network (str_stripped))
810  return HOST_TYPE_RANGE6_SHORT;
811 
812  /* Check for long IPv6 range-expressed networks like "::1:20:7-::1:25:3" */
813  if (is_long_range6_network (str_stripped))
814  return HOST_TYPE_RANGE6_LONG;
815 
816  /* Check for hostname. */
817  if (is_hostname (str_stripped))
818  return HOST_TYPE_NAME;
819 
820  return -1;
821 }

References HOST_TYPE_CIDR6_BLOCK, HOST_TYPE_CIDR_BLOCK, HOST_TYPE_IPV4, HOST_TYPE_IPV6, HOST_TYPE_NAME, HOST_TYPE_RANGE6_LONG, HOST_TYPE_RANGE6_SHORT, HOST_TYPE_RANGE_LONG, HOST_TYPE_RANGE_SHORT, is_cidr6_block(), is_cidr_block(), is_hostname(), is_ipv4_address(), is_ipv6_address(), is_long_range6_network(), is_long_range_network(), is_short_range6_network(), and is_short_range_network().

Referenced by gvm_hosts_new_with_max(), gvm_server_open_verify(), and osp_send_command().

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

◆ gvm_host_add_reverse_lookup()

void gvm_host_add_reverse_lookup ( gvm_host_t host)

Add a host's reverse-lookup name to the vhosts list.

Parameters
[in]hostThe host to which we add the vhost.

Definition at line 1633 of file hosts.c.

1634 {
1635  GSList *vhosts;
1636  gvm_vhost_t *vhost;
1637  char *value;
1638 
1639  if (!host || host->type == HOST_TYPE_NAME)
1640  return;
1641 
1642  value = gvm_host_reverse_lookup (host);
1643  if (!value)
1644  return;
1645  if (host_name_verify (host, value))
1646  {
1647  g_free (value);
1648  return;
1649  }
1650  /* Don't add vhost, if already in the list. */
1651  vhosts = host->vhosts;
1652  while (vhosts)
1653  {
1654  if (!strcasecmp (((gvm_vhost_t *) vhosts->data)->value, value))
1655  {
1656  g_free (value);
1657  return;
1658  }
1659  vhosts = vhosts->next;
1660  }
1661  vhost = gvm_vhost_new (value, g_strdup ("Reverse-DNS"));
1662  host->vhosts = g_slist_prepend (host->vhosts, vhost);
1663 }

References gvm_host_reverse_lookup(), gvm_vhost_new(), host_name_verify(), HOST_TYPE_NAME, gvm_host::type, and gvm_host::vhosts.

Here is the call graph for this function:

◆ gvm_host_get_addr6()

int gvm_host_get_addr6 ( const gvm_host_t host,
struct in6_addr *  ip6 
)

Gives a host object's value as an IPv6 address. If the host type is hostname, it resolves the IPv4 address then gives an IPv4-mapped IPv6 address (eg. ::ffff:192.168.1.1 .) If the host type is IPv4, it gives an IPv4-mapped IPv6 address. If the host's type is IPv6, it gives the value directly.

Parameters
[in]hostThe host object whose value to get as IPv6.
[out]ip6Buffer to store the IPv6 address.
Returns
-1 if error, 0 otherwise.

Definition at line 1955 of file hosts.c.

1956 {
1957  if (host == NULL || ip6 == NULL)
1958  return -1;
1959 
1960  switch (gvm_host_type (host))
1961  {
1962  case HOST_TYPE_IPV6:
1963  memcpy (ip6, &host->addr6, sizeof (struct in6_addr));
1964  return 0;
1965 
1966  case HOST_TYPE_IPV4:
1967  ipv4_as_ipv6 (&host->addr, ip6);
1968  return 0;
1969 
1970  case HOST_TYPE_NAME:
1971  {
1972  struct in_addr ip4;
1973 
1974  /* Fail if IPv4 and IPv6 both don't resolve. */
1975  if (gvm_host_resolve (host, &ip4, AF_INET) == 0)
1976  ipv4_as_ipv6 (&ip4, ip6);
1977  else if (gvm_host_resolve (host, ip6, AF_INET6) == -1)
1978  return -1;
1979  return 0;
1980  }
1981 
1982  default:
1983  return -1;
1984  }
1985 }

References gvm_host::addr, gvm_host::addr6, gvm_host_resolve(), gvm_host_type(), HOST_TYPE_IPV4, HOST_TYPE_IPV6, HOST_TYPE_NAME, and ipv4_as_ipv6().

Referenced by gvm_host_in_hosts().

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

◆ gvm_host_in_hosts()

int gvm_host_in_hosts ( const gvm_host_t host,
const struct in6_addr *  addr,
const gvm_hosts_t hosts 
)

Returns whether a host has an equal host in a hosts collection. eg. 192.168.10.1 has an equal in list created from "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't.

Parameters
[in]hostThe host object.
[in]addrOptional pointer to ip address. Could be used so that host isn't resolved multiple times when type is HOST_TYPE_NAME.
[in]hostsHosts collection.
Returns
1 if host has equal in hosts, 0 otherwise.

Definition at line 1796 of file hosts.c.

1798 {
1799  char *host_str;
1800  size_t i;
1801 
1802  if (host == NULL || hosts == NULL)
1803  return 0;
1804 
1805  host_str = gvm_host_value_str (host);
1806 
1807  for (i = 0; i < hosts->count; i++)
1808  {
1809  gvm_host_t *current_host = hosts->hosts[i];
1810  char *tmp = gvm_host_value_str (current_host);
1811 
1812  if (strcasecmp (host_str, tmp) == 0)
1813  {
1814  g_free (host_str);
1815  g_free (tmp);
1816  return 1;
1817  }
1818  g_free (tmp);
1819 
1820  /* Hostnames in hosts list shouldn't be resolved. */
1821  if (addr && gvm_host_type (current_host) != HOST_TYPE_NAME)
1822  {
1823  struct in6_addr tmpaddr;
1824  gvm_host_get_addr6 (current_host, &tmpaddr);
1825 
1826  if (memcmp (addr->s6_addr, &tmpaddr.s6_addr, 16) == 0)
1827  {
1828  g_free (host_str);
1829  return 1;
1830  }
1831  }
1832  }
1833 
1834  g_free (host_str);
1835  return 0;
1836 }

References gvm_hosts::count, gvm_host_get_addr6(), gvm_host_type(), gvm_host_value_str(), HOST_TYPE_NAME, and gvm_hosts::hosts.

Here is the call graph for this function:

◆ gvm_host_resolve()

int gvm_host_resolve ( const gvm_host_t host,
void *  dst,
int  family 
)

Resolves a host object's name to an IPv4 or IPv6 address. Host object should be of type HOST_TYPE_NAME.

Parameters
[in]hostThe host object whose name to resolve.
[out]dstBuffer to store resolved address. Size must be at least 4 bytes for AF_INET and 16 bytes for AF_INET6.
[in]familyEither AF_INET or AF_INET6.
Returns
-1 if error, 0 otherwise.

Definition at line 1934 of file hosts.c.

1935 {
1936  if (host == NULL || dst == NULL || host->type != HOST_TYPE_NAME)
1937  return -1;
1938 
1939  return gvm_resolve (host->name, dst, family);
1940 }

References gvm_resolve(), HOST_TYPE_NAME, gvm_host::name, and gvm_host::type.

Referenced by gvm_host_get_addr6().

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

◆ gvm_host_reverse_lookup()

char* gvm_host_reverse_lookup ( gvm_host_t host)

Checks for a host object reverse dns lookup existence.

Parameters
[in]hostThe host to reverse-lookup.
Returns
Result of look-up, NULL otherwise.

Definition at line 1549 of file hosts.c.

1550 {
1551  int retry = 2;
1552  gchar hostname[NI_MAXHOST];
1553  void *addr;
1554  size_t addrlen;
1555  struct sockaddr_in sa;
1556  struct sockaddr_in6 sa6;
1557 
1558  if (!host)
1559  return NULL;
1560 
1561  if (host->type == HOST_TYPE_IPV4)
1562  {
1563  addr = &sa;
1564  addrlen = sizeof (sa);
1565  memset (addr, '\0', addrlen);
1566  sa.sin_addr = host->addr;
1567  sa.sin_family = AF_INET;
1568  }
1569  else if (host->type == HOST_TYPE_IPV6)
1570  {
1571  addr = &sa6;
1572  addrlen = sizeof (sa6);
1573  memset (&sa6, '\0', addrlen);
1574  memcpy (&sa6.sin6_addr, &host->addr6, 16);
1575  sa6.sin6_family = AF_INET6;
1576  }
1577  else
1578  return NULL;
1579 
1580  while (retry--)
1581  {
1582  int ret = getnameinfo (addr, addrlen, hostname, sizeof (hostname), NULL,
1583  0, NI_NAMEREQD);
1584  if (!ret)
1585  return g_ascii_strdown (hostname, -1);
1586  if (ret != EAI_AGAIN)
1587  break;
1588  }
1589  return NULL;
1590 }

References gvm_host::addr, gvm_host::addr6, HOST_TYPE_IPV4, HOST_TYPE_IPV6, and gvm_host::type.

Referenced by gvm_host_add_reverse_lookup(), gvm_hosts_reverse_lookup_only(), and gvm_hosts_reverse_lookup_unify().

Here is the caller graph for this function:

◆ gvm_host_type()

enum host_type gvm_host_type ( const gvm_host_t host)

Gets a host object's type.

Parameters
[in]hostThe host object.
Returns
Host type.

Definition at line 1846 of file hosts.c.

1847 {
1848  assert (host);
1849  return host->type;
1850 }

References gvm_host::type.

Referenced by gvm_host_get_addr6(), and gvm_host_in_hosts().

Here is the caller graph for this function:

◆ gvm_host_type_str()

gchar* gvm_host_type_str ( const gvm_host_t host)

Gets a host's type in printable format.

Parameters
[in]hostThe host object.
Returns
String representing host type. Statically allocated, thus, not to be freed.

Definition at line 1861 of file hosts.c.

1862 {
1863  if (host == NULL)
1864  return NULL;
1865 
1866  return host_type_str[host->type];
1867 }

References host_type_str, and gvm_host::type.

◆ gvm_host_value_str()

gchar* gvm_host_value_str ( const gvm_host_t host)

Gets a host's value in printable format.

Parameters
[in]hostThe host object.
Returns
String representing host value. To be freed with g_free().

Definition at line 1877 of file hosts.c.

1878 {
1879  if (host == NULL)
1880  return NULL;
1881 
1882  switch (host->type)
1883  {
1884  case HOST_TYPE_NAME:
1885  return g_strdup (host->name);
1886  break;
1887  case HOST_TYPE_IPV4:
1888  case HOST_TYPE_IPV6:
1889  /* Handle both cases using inet_ntop(). */
1890  {
1891  int family, size;
1892  gchar *str;
1893  const void *srcaddr;
1894 
1895  if (host->type == HOST_TYPE_IPV4)
1896  {
1897  family = AF_INET;
1898  size = INET_ADDRSTRLEN;
1899  srcaddr = &host->addr;
1900  }
1901  else
1902  {
1903  family = AF_INET6;
1904  size = INET6_ADDRSTRLEN;
1905  srcaddr = &host->addr6;
1906  }
1907 
1908  str = g_malloc0 (size);
1909  if (inet_ntop (family, srcaddr, str, size) == NULL)
1910  {
1911  perror ("inet_ntop");
1912  g_free (str);
1913  return NULL;
1914  }
1915  return str;
1916  }
1917  default:
1918  return g_strdup ("Erroneous host type: Should be Hostname/IPv4/IPv6.");
1919  }
1920 }

References gvm_host::addr, gvm_host::addr6, HOST_TYPE_IPV4, HOST_TYPE_IPV6, HOST_TYPE_NAME, gvm_host::name, and gvm_host::type.

Referenced by gvm_host_in_hosts(), gvm_hosts_deduplicate(), gvm_hosts_exclude_with_max(), and host_name_verify().

Here is the caller graph for this function:

◆ gvm_hosts_count()

unsigned int gvm_hosts_count ( const gvm_hosts_t hosts)

Gets the count of single hosts objects in a hosts collection.

Parameters
[in]hostsThe hosts collection to count hosts of.
Returns
The number of single hosts.

Definition at line 1764 of file hosts.c.

1765 {
1766  return hosts ? hosts->count : 0;
1767 }

References gvm_hosts::count.

Referenced by gvm_hosts_exclude_with_max().

Here is the caller graph for this function:

◆ gvm_hosts_exclude()

int gvm_hosts_exclude ( gvm_hosts_t hosts,
const char *  excluded_str 
)

Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection from which to exclude.
[in]excluded_strString of hosts to exclude.
Returns
Number of excluded hosts, -1 if error.

Definition at line 1536 of file hosts.c.

1537 {
1538  return gvm_hosts_exclude_with_max (hosts, excluded_str, 0);
1539 }

References gvm_hosts_exclude_with_max().

Here is the call graph for this function:

◆ gvm_hosts_exclude_with_max()

int gvm_hosts_exclude_with_max ( gvm_hosts_t hosts,
const char *  excluded_str,
unsigned int  max_hosts 
)

Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection from which to exclude.
[in]excluded_strString of hosts to exclude.
[in]max_hostsMax number of hosts in hosts_str. 0 means unlimited.
Returns
Number of excluded hosts, -1 if error.

Uses a hash table in order to exclude hosts in O(N+M) time.

Definition at line 1462 of file hosts.c.

1464 {
1468  gvm_hosts_t *excluded_hosts;
1469  GHashTable *name_table;
1470  size_t excluded = 0, i;
1471 
1472  if (hosts == NULL || excluded_str == NULL)
1473  return -1;
1474 
1475  excluded_hosts = gvm_hosts_new_with_max (excluded_str, max_hosts);
1476  if (excluded_hosts == NULL)
1477  return -1;
1478 
1479  if (gvm_hosts_count (excluded_hosts) == 0)
1480  {
1481  gvm_hosts_free (excluded_hosts);
1482  return 0;
1483  }
1484 
1485  /* Hash host values from excluded hosts list. */
1486  name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1487  for (i = 0; i < excluded_hosts->count; i++)
1488  {
1489  gchar *name;
1490 
1491  if ((name = gvm_host_value_str (excluded_hosts->hosts[i])))
1492  g_hash_table_insert (name_table, name, hosts);
1493  }
1494 
1495  /* Check for hosts values in hash table. */
1496  for (i = 0; i < hosts->count; i++)
1497  {
1498  gchar *name;
1499 
1500  if ((name = gvm_host_value_str (hosts->hosts[i])))
1501  {
1502  if (g_hash_table_lookup (name_table, name))
1503  {
1504  gvm_host_free (hosts->hosts[i]);
1505  hosts->hosts[i] = NULL;
1506  excluded++;
1507  g_free (name);
1508  continue;
1509  }
1510  g_free (name);
1511  }
1512  }
1513 
1514  /* Cleanup. */
1515  if (excluded)
1516  gvm_hosts_fill_gaps (hosts);
1517  hosts->count -= excluded;
1518  hosts->removed += excluded;
1519  hosts->current = 0;
1520  g_hash_table_destroy (name_table);
1521  gvm_hosts_free (excluded_hosts);
1522  return excluded;
1523 }

References gvm_hosts::count, gvm_hosts::current, gvm_host_free(), gvm_host_value_str(), gvm_hosts_count(), gvm_hosts_fill_gaps(), gvm_hosts_free(), gvm_hosts_new_with_max(), gvm_hosts::hosts, and gvm_hosts::removed.

Referenced by gvm_hosts_exclude().

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

◆ gvm_hosts_free()

void gvm_hosts_free ( gvm_hosts_t hosts)

Frees memory occupied by an gvm_hosts_t structure.

Parameters
[in]hostsThe hosts collection to free.

Definition at line 1258 of file hosts.c.

1259 {
1260  size_t i;
1261 
1262  if (hosts == NULL)
1263  return;
1264 
1265  if (hosts->orig_str)
1266  g_free (hosts->orig_str);
1267  for (i = 0; i < hosts->count; i++)
1268  gvm_host_free (hosts->hosts[i]);
1269  g_free (hosts->hosts);
1270  g_free (hosts);
1271 }

References gvm_hosts::count, gvm_host_free(), gvm_hosts::hosts, and gvm_hosts::orig_str.

Referenced by gvm_hosts_exclude_with_max(), and gvm_hosts_new_with_max().

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

◆ gvm_hosts_new()

gvm_hosts_t* gvm_hosts_new ( const gchar *  hosts_str)

Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str.

Parameters
[in]hosts_strThe hosts string. A copy will be created of this within the returned struct.
Returns
NULL if error, otherwise, a hosts structure that should be released using gvm_hosts_free.

Definition at line 1229 of file hosts.c.

1230 {
1231  return gvm_hosts_new_with_max (hosts_str, 0);
1232 }

References gvm_hosts_new_with_max().

Here is the call graph for this function:

◆ gvm_hosts_new_with_max()

gvm_hosts_t* gvm_hosts_new_with_max ( const gchar *  hosts_str,
unsigned int  max_hosts 
)

Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str.

Parameters
[in]hosts_strThe hosts string. A copy will be created of this within the returned struct.
[in]max_hostsMax number of hosts in hosts_str. 0 means unlimited.
Returns
NULL if error or hosts_str contains more than max hosts. Otherwise, a hosts structure that should be released using gvm_hosts_free.

Definition at line 1034 of file hosts.c.

1035 {
1036  gvm_hosts_t *hosts;
1037  gchar **host_element, **split;
1038  gchar *str;
1039 
1040  if (hosts_str == NULL)
1041  return NULL;
1042 
1043  /* Normalize separator: Transform newlines into commas. */
1044  hosts = gvm_hosts_init (hosts_str);
1045  str = hosts->orig_str;
1046  while (*str)
1047  {
1048  if (*str == '\n')
1049  *str = ',';
1050  str++;
1051  }
1052 
1053  /* Split comma-separated list into single host-specifications */
1054  split = g_strsplit (hosts->orig_str, ",", 0);
1055 
1056  /* first element of the split list */
1057  host_element = split;
1058  while (*host_element)
1059  {
1060  int host_type;
1061  gchar *stripped = g_strstrip (*host_element);
1062 
1063  if (stripped == NULL || *stripped == '\0')
1064  {
1065  host_element++;
1066  continue;
1067  }
1068 
1069  /* IPv4, hostname, IPv6, collection (short/long range, cidr block) etc,. ?
1070  */
1071  /* -1 if error. */
1072  host_type = gvm_get_host_type (stripped);
1073 
1074  switch (host_type)
1075  {
1076  case HOST_TYPE_NAME:
1077  case HOST_TYPE_IPV4:
1078  case HOST_TYPE_IPV6:
1079  {
1080  /* New host. */
1081  gvm_host_t *host = gvm_host_new ();
1082  host->type = host_type;
1083  if (host_type == HOST_TYPE_NAME)
1084  host->name = g_ascii_strdown (stripped, -1);
1085  else if (host_type == HOST_TYPE_IPV4)
1086  {
1087  if (inet_pton (AF_INET, stripped, &host->addr) != 1)
1088  break;
1089  }
1090  else if (host_type == HOST_TYPE_IPV6)
1091  {
1092  if (inet_pton (AF_INET6, stripped, &host->addr6) != 1)
1093  break;
1094  }
1095  gvm_hosts_add (hosts, host);
1096  break;
1097  }
1098  case HOST_TYPE_CIDR_BLOCK:
1099  case HOST_TYPE_RANGE_SHORT:
1100  case HOST_TYPE_RANGE_LONG:
1101  {
1102  struct in_addr first, last;
1103  uint32_t current;
1104  int (*ips_func) (const char *, struct in_addr *, struct in_addr *);
1105 
1107  ips_func = cidr_block_ips;
1108  else if (host_type == HOST_TYPE_RANGE_SHORT)
1109  ips_func = short_range_network_ips;
1110  else
1111  ips_func = long_range_network_ips;
1112 
1113  if (ips_func (stripped, &first, &last) == -1)
1114  break;
1115 
1116  /* Make sure that first actually comes before last */
1117  if (ntohl (first.s_addr) > ntohl (last.s_addr))
1118  break;
1119 
1120  /* Add addresses from first to last as single hosts. */
1121  current = first.s_addr;
1122  while (ntohl (current) <= ntohl (last.s_addr))
1123  {
1124  gvm_host_t *host;
1125  if (max_hosts > 0 && hosts->count > max_hosts)
1126  {
1127  g_strfreev (split);
1128  gvm_hosts_free (hosts);
1129  return NULL;
1130  }
1131  host = gvm_host_new ();
1132  host->type = HOST_TYPE_IPV4;
1133  host->addr.s_addr = current;
1134  gvm_hosts_add (hosts, host);
1135  /* Next IP address. */
1136  current = htonl (ntohl (current) + 1);
1137  }
1138  break;
1139  }
1140  case HOST_TYPE_CIDR6_BLOCK:
1141  case HOST_TYPE_RANGE6_LONG:
1143  {
1144  struct in6_addr first, last;
1145  unsigned char current[16];
1146  int (*ips_func) (const char *, struct in6_addr *,
1147  struct in6_addr *);
1148 
1150  ips_func = cidr6_block_ips;
1151  else if (host_type == HOST_TYPE_RANGE6_SHORT)
1152  ips_func = short_range6_network_ips;
1153  else
1154  ips_func = long_range6_network_ips;
1155 
1156  if (ips_func (stripped, &first, &last) == -1)
1157  break;
1158 
1159  /* Make sure the first comes before the last. */
1160  if (memcmp (&first.s6_addr, &last.s6_addr, 16) > 0)
1161  break;
1162 
1163  /* Add addresses from first to last as single hosts. */
1164  memcpy (current, &first.s6_addr, 16);
1165  while (memcmp (current, &last.s6_addr, 16) <= 0)
1166  {
1167  int i;
1168  gvm_host_t *host;
1169 
1170  if (max_hosts > 0 && hosts->count > max_hosts)
1171  {
1172  g_strfreev (split);
1173  gvm_hosts_free (hosts);
1174  return NULL;
1175  }
1176  host = gvm_host_new ();
1177  host->type = HOST_TYPE_IPV6;
1178  memcpy (host->addr6.s6_addr, current, 16);
1179  gvm_hosts_add (hosts, host);
1180  /* Next IPv6 address. */
1181  for (i = 15; i >= 0; --i)
1182  if (current[i] < 255)
1183  {
1184  current[i]++;
1185  break;
1186  }
1187  else
1188  current[i] = 0;
1189  }
1190  break;
1191  }
1192  case -1:
1193  default:
1194  /* Invalid host string. */
1195  g_strfreev (split);
1196  gvm_hosts_free (hosts);
1197  return NULL;
1198  }
1199  host_element++; /* move on to next element of split list */
1200  if (max_hosts > 0 && hosts->count > max_hosts)
1201  {
1202  g_strfreev (split);
1203  gvm_hosts_free (hosts);
1204  return NULL;
1205  }
1206  }
1207 
1208  /* No need to check for duplicates when a hosts string contains a
1209  * single (IP/Hostname/Range/Subnetwork) entry. */
1210  if (g_strv_length (split) > 1)
1211  gvm_hosts_deduplicate (hosts);
1212 
1213  g_strfreev (split);
1214  malloc_trim (0);
1215  return hosts;
1216 }

References gvm_host::addr, gvm_host::addr6, cidr6_block_ips(), cidr_block_ips(), gvm_hosts::count, gvm_get_host_type(), gvm_host_new(), gvm_hosts_add(), gvm_hosts_deduplicate(), gvm_hosts_free(), gvm_hosts_init(), HOST_TYPE_CIDR6_BLOCK, HOST_TYPE_CIDR_BLOCK, HOST_TYPE_IPV4, HOST_TYPE_IPV6, HOST_TYPE_NAME, HOST_TYPE_RANGE6_LONG, HOST_TYPE_RANGE6_SHORT, HOST_TYPE_RANGE_LONG, HOST_TYPE_RANGE_SHORT, long_range6_network_ips(), long_range_network_ips(), gvm_host::name, gvm_hosts::orig_str, short_range6_network_ips(), short_range_network_ips(), and gvm_host::type.

Referenced by gvm_hosts_exclude_with_max(), and gvm_hosts_new().

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

◆ gvm_hosts_next()

gvm_host_t* gvm_hosts_next ( gvm_hosts_t hosts)

Gets the next gvm_host_t from a gvm_hosts_t structure. The state of iteration is kept internally within the gvm_hosts structure.

Parameters
[in]hostsgvm_hosts_t structure to get next host from.
Returns
Pointer to host. NULL if error or end of hosts.

Definition at line 1243 of file hosts.c.

1244 {
1245  if (!hosts || hosts->current == hosts->count)
1246  return NULL;
1247 
1248  return hosts->hosts[hosts->current++];
1249 }

References gvm_hosts::count, gvm_hosts::current, and gvm_hosts::hosts.

◆ gvm_hosts_removed()

unsigned int gvm_hosts_removed ( const gvm_hosts_t hosts)

Gets the count of single values in hosts string that were removed (duplicates / excluded.)

Parameters
[in]hostsThe hosts collection.
Returns
The number of removed values.

Definition at line 1778 of file hosts.c.

1779 {
1780  return hosts ? hosts->removed : 0;
1781 }

References gvm_hosts::removed.

◆ gvm_hosts_resolve()

GSList* gvm_hosts_resolve ( gvm_hosts_t hosts)

Resolves host objects of type name in a hosts collection, replacing hostnames with IPv4 values. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection from which to exclude.
Returns
List of unresolved hostnames.

Definition at line 1339 of file hosts.c.

1340 {
1341  size_t i, new_entries = 0, resolved = 0;
1342  GSList *unresolved = NULL;
1343 
1344  for (i = 0; i < hosts->count; i++)
1345  {
1346  GSList *list, *tmp;
1347  gvm_host_t *host = hosts->hosts[i];
1348 
1349  if (host->type != HOST_TYPE_NAME)
1350  continue;
1351 
1352  list = tmp = gvm_resolve_list (host->name);
1353  while (tmp)
1354  {
1355  /* Create a new host for each IP address. */
1356  gvm_host_t *new;
1357  struct in6_addr *ip6 = tmp->data;
1358  gvm_vhost_t *vhost;
1359 
1360  new = gvm_host_new ();
1361  if (ip6->s6_addr32[0] != 0 || ip6->s6_addr32[1] != 0
1362  || ip6->s6_addr32[2] != htonl (0xffff))
1363  {
1364  new->type = HOST_TYPE_IPV6;
1365  memcpy (&new->addr6, ip6, sizeof (new->addr6));
1366  }
1367  else
1368  {
1369  new->type = HOST_TYPE_IPV4;
1370  memcpy (&new->addr6, &ip6->s6_addr32[3], sizeof (new->addr));
1371  }
1372  vhost =
1373  gvm_vhost_new (g_strdup (host->name), g_strdup ("Forward-DNS"));
1374  new->vhosts = g_slist_prepend (new->vhosts, vhost);
1375  gvm_hosts_add (hosts, new);
1376  tmp = tmp->next;
1377  new_entries = 1;
1378  }
1379  /* Remove hostname from list, as it was either replaced by IPs, or
1380  * is unresolvable. */
1381  hosts->hosts[i] = NULL;
1382  resolved++;
1383  if (!list)
1384  unresolved = g_slist_prepend (unresolved, g_strdup (host->name));
1385  gvm_host_free (host);
1386  g_slist_free_full (list, g_free);
1387  }
1388  if (resolved)
1389  gvm_hosts_fill_gaps (hosts);
1390  hosts->count -= resolved;
1391  hosts->removed += resolved;
1392  if (new_entries)
1393  gvm_hosts_deduplicate (hosts);
1394  hosts->current = 0;
1395  return unresolved;
1396 }

References gvm_hosts::count, gvm_hosts::current, gvm_host_free(), gvm_host_new(), gvm_hosts_add(), gvm_hosts_deduplicate(), gvm_hosts_fill_gaps(), gvm_resolve_list(), gvm_vhost_new(), HOST_TYPE_IPV4, HOST_TYPE_IPV6, HOST_TYPE_NAME, gvm_hosts::hosts, gvm_host::name, gvm_hosts::removed, and gvm_host::type.

Here is the call graph for this function:

◆ gvm_hosts_reverse()

void gvm_hosts_reverse ( gvm_hosts_t hosts)

Reverses the order of the hosts objects in the collection. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection to reverse.

Definition at line 1313 of file hosts.c.

1314 {
1315  size_t i, j;
1316  if (hosts == NULL)
1317  return;
1318 
1319  for (i = 0, j = hosts->count - 1; i < j; i++, j--)
1320  {
1321  gvm_host_t *tmp = hosts->hosts[i];
1322  hosts->hosts[i] = hosts->hosts[j];
1323  hosts->hosts[j] = tmp;
1324  }
1325  hosts->current = 0;
1326 }

References gvm_hosts::count, gvm_hosts::current, and gvm_hosts::hosts.

◆ gvm_hosts_reverse_lookup_only()

int gvm_hosts_reverse_lookup_only ( gvm_hosts_t hosts)

Removes hosts that don't reverse-lookup from the hosts collection. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection to filter.
Returns
Number of hosts removed, -1 if error.

Definition at line 1675 of file hosts.c.

1676 {
1677  size_t i, count = 0;
1678 
1679  if (hosts == NULL)
1680  return -1;
1681 
1682  for (i = 0; i < hosts->count; i++)
1683  {
1684  gchar *name = gvm_host_reverse_lookup (hosts->hosts[i]);
1685 
1686  if (name == NULL)
1687  {
1688  gvm_host_free (hosts->hosts[i]);
1689  hosts->hosts[i] = NULL;
1690  count++;
1691  }
1692  else
1693  g_free (name);
1694  }
1695 
1696  if (count)
1697  gvm_hosts_fill_gaps (hosts);
1698  hosts->count -= count;
1699  hosts->removed += count;
1700  hosts->current = 0;
1701  return count;
1702 }

References gvm_hosts::count, gvm_hosts::current, gvm_host_free(), gvm_host_reverse_lookup(), gvm_hosts_fill_gaps(), gvm_hosts::hosts, and gvm_hosts::removed.

Here is the call graph for this function:

◆ gvm_hosts_reverse_lookup_unify()

int gvm_hosts_reverse_lookup_unify ( gvm_hosts_t hosts)

Removes hosts duplicates that reverse-lookup to the same value. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection to filter.
Returns
Number of hosts removed, -1 if error.

Uses a hash table in order to unify the hosts list in O(N) time.

Definition at line 1714 of file hosts.c.

1715 {
1719  size_t i, count = 0;
1720  GHashTable *name_table;
1721 
1722  if (hosts == NULL)
1723  return -1;
1724 
1725  name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1726  for (i = 0; i < hosts->count; i++)
1727  {
1728  gchar *name;
1729 
1730  if ((name = gvm_host_reverse_lookup (hosts->hosts[i])))
1731  {
1732  if (g_hash_table_lookup (name_table, name))
1733  {
1734  gvm_host_free (hosts->hosts[i]);
1735  hosts->hosts[i] = NULL;
1736  count++;
1737  g_free (name);
1738  }
1739  else
1740  {
1741  /* Insert in the hash table. Value not important. */
1742  g_hash_table_insert (name_table, name, hosts);
1743  }
1744  }
1745  }
1746 
1747  if (count)
1748  gvm_hosts_fill_gaps (hosts);
1749  g_hash_table_destroy (name_table);
1750  hosts->removed += count;
1751  hosts->count -= count;
1752  hosts->current = 0;
1753  return count;
1754 }

References gvm_hosts::count, gvm_hosts::current, gvm_host_free(), gvm_host_reverse_lookup(), gvm_hosts_fill_gaps(), gvm_hosts::hosts, and gvm_hosts::removed.

Here is the call graph for this function:

◆ gvm_hosts_shuffle()

void gvm_hosts_shuffle ( gvm_hosts_t hosts)

Randomizes the order of the hosts objects in the collection. Not to be used while iterating over the single hosts as it resets the iterator.

Parameters
[in]hostsThe hosts collection to shuffle.

Definition at line 1281 of file hosts.c.

1282 {
1283  size_t i = 0;
1284  GRand *rand;
1285 
1286  if (hosts == NULL)
1287  return;
1288 
1289  /* Shuffle the array. */
1290  rand = g_rand_new ();
1291  for (i = 0; i < hosts->count; i++)
1292  {
1293  void *tmp;
1294  int j = g_rand_int_range (rand, 0, hosts->count);
1295 
1296  tmp = hosts->hosts[i];
1297  hosts->hosts[i] = hosts->hosts[j];
1298  hosts->hosts[j] = tmp;
1299  }
1300 
1301  hosts->current = 0;
1302  g_rand_free (rand);
1303 }

References gvm_hosts::count, gvm_hosts::current, and gvm_hosts::hosts.

◆ gvm_vhost_new()

gvm_vhost_t* gvm_vhost_new ( char *  value,
char *  source 
)

Creates a new gvm_vhost_t object.

Parameters
[in]valueVhost value.
[in]sourceSource of hostname.
Returns
Pointer to new vhost object.

Definition at line 832 of file hosts.c.

833 {
834  gvm_vhost_t *vhost;
835 
836  vhost = g_malloc0 (sizeof (gvm_vhost_t));
837  vhost->value = value;
838  vhost->source = source;
839 
840  return vhost;
841 }

References gvm_vhost::source, and gvm_vhost::value.

Referenced by gvm_host_add_reverse_lookup(), and gvm_hosts_resolve().

Here is the caller graph for this function:

◆ gvm_vhosts_exclude()

int gvm_vhosts_exclude ( gvm_host_t host,
const char *  excluded_str 
)

Exclude a list of vhosts from a host's vhosts list.

Parameters
[in]hostThe host whose vhosts are to be excluded from.
[in]excluded_strString of hosts to exclude.
Returns
Number of excluded vhosts.

Definition at line 1407 of file hosts.c.

1408 {
1409  GSList *vhost;
1410  char **excluded;
1411  int ret = 0;
1412 
1413  if (!host || !excluded_str)
1414  return ret;
1415 
1416  vhost = host->vhosts;
1417  excluded = g_strsplit (excluded_str, ",", 0);
1418  if (!excluded || !*excluded)
1419  {
1420  g_strfreev (excluded);
1421  return ret;
1422  }
1423  while (vhost)
1424  {
1425  char **tmp = excluded;
1426  char *value = ((gvm_vhost_t *) vhost->data)->value;
1427 
1428  while (*tmp)
1429  {
1430  if (!strcasecmp (value, g_strstrip (*tmp)))
1431  {
1432  gvm_vhost_free (vhost->data);
1433  host->vhosts = vhost = g_slist_delete_link (host->vhosts, vhost);
1434  ret++;
1435  break;
1436  }
1437  tmp++;
1438  if (!*tmp)
1439  {
1440  vhost = vhost->next;
1441  break;
1442  }
1443  }
1444  }
1445  g_strfreev (excluded);
1446 
1447  return ret;
1448 }

References gvm_vhost_free(), and gvm_host::vhosts.

Here is the call graph for this function:
gvm_host_value_str
gchar * gvm_host_value_str(const gvm_host_t *host)
Gets a host's value in printable format.
Definition: hosts.c:1877
long_range6_network_ips
static int long_range6_network_ips(const char *str, struct in6_addr *first, struct in6_addr *last)
Gets the first and last IPv6 addresses from a long range-expressed network. eg. "::1:200:7-::1:205:50...
Definition: hosts.c:637
gvm_host::name
gchar * name
Definition: hosts.h:67
cidr6_block_ips
static int cidr6_block_ips(const char *str, struct in6_addr *first, struct in6_addr *last)
Gets the first and last usable IPv4 addresses from a CIDR-expressed block. eg. "192....
Definition: hosts.c:530
long_range_network_ips
static int long_range_network_ips(const char *str, struct in_addr *first, struct in_addr *last)
Gets the first and last IPv4 addresses from a long range-expressed network. eg. "192....
Definition: hosts.c:277
is_short_range_network
static int is_short_range_network(const char *str)
Checks if a buffer points to a valid short range-expressed network. "192.168.11.1-50" is valid,...
Definition: hosts.c:317
is_hostname
static int is_hostname(const char *str)
Checks if a buffer points to a valid hostname. Valid characters include: Alphanumerics,...
Definition: hosts.c:408
gvm_hosts::count
size_t count
Definition: hosts.h:96
gvm_hosts::removed
size_t removed
Definition: hosts.h:97
gvm_hosts_free
void gvm_hosts_free(gvm_hosts_t *hosts)
Frees memory occupied by an gvm_hosts_t structure.
Definition: hosts.c:1258
gvm_resolve_list
GSList * gvm_resolve_list(const char *name)
Returns a list of addresses that a hostname resolves to.
Definition: networking.c:338
is_long_range_network
static int is_long_range_network(const char *str)
Checks if a buffer points to a valid long range-expressed network. "192.168.12.1-192....
Definition: hosts.c:242
gvm_hosts_init
static gvm_hosts_t * gvm_hosts_init(const char *hosts_str)
Creates a hosts collection from a hosts string.
Definition: hosts.c:921
is_cidr6_block
static int is_cidr6_block(const char *str)
Checks if a buffer points to an IPv6 CIDR-expressed block. "2620:0:2d0:200::7/120" is valid,...
Definition: hosts.c:431
ipv4_as_ipv6
void ipv4_as_ipv6(const struct in_addr *ip4, struct in6_addr *ip6)
Maps an IPv4 address as an IPv6 address. eg. 192.168.10.20 would map to ::ffff:192....
Definition: networking.c:242
HOST_TYPE_IPV6
@ HOST_TYPE_IPV6
Definition: hosts.h:43
gvm_host_free
static void gvm_host_free(gpointer host)
Frees the memory occupied by an gvm_host_t object.
Definition: hosts.c:880
short_range6_network_ips
static int short_range6_network_ips(const char *str, struct in6_addr *first, struct in6_addr *last)
Gets the first and last IPv6 addresses from a short range-expressed network. eg. "\::ffee:1:1001-1005...
Definition: hosts.c:725
gvm_hosts_count
unsigned int gvm_hosts_count(const gvm_hosts_t *hosts)
Gets the count of single hosts objects in a hosts collection.
Definition: hosts.c:1764
is_long_range6_network
static int is_long_range6_network(const char *str)
Checks if a buffer points to a valid long IPv6 range-expressed network. "::fee5-::1:530" is valid.
Definition: hosts.c:602
HOST_TYPE_RANGE_SHORT
@ HOST_TYPE_RANGE_SHORT
Definition: hosts.h:41
gvm_hosts_new_with_max
gvm_hosts_t * gvm_hosts_new_with_max(const gchar *hosts_str, unsigned int max_hosts)
Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str.
Definition: hosts.c:1034
gvm_host::type
enum host_type type
Definition: hosts.h:71
gvm_resolve
int gvm_resolve(const char *name, void *dst, int family)
Resolves a hostname to an IPv4 or IPv6 address.
Definition: networking.c:388
gvm_host_get_addr6
int gvm_host_get_addr6(const gvm_host_t *host, struct in6_addr *ip6)
Gives a host object's value as an IPv6 address. If the host type is hostname, it resolves the IPv4 ad...
Definition: hosts.c:1955
gvm_vhost
The structure for a single vhost object.
Definition: hosts.h:78
HOST_TYPE_IPV4
@ HOST_TYPE_IPV4
Definition: hosts.h:39
gvm_hosts_add
static void gvm_hosts_add(gvm_hosts_t *hosts, gvm_host_t *host)
Inserts a host object at the end of a hosts collection.
Definition: hosts.c:901
gvm_hosts::hosts
gvm_host_t ** hosts
Definition: hosts.h:93
gvm_get_host_type
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
Definition: hosts.c:771
gvm_host
The structure for a single host object.
Definition: hosts.h:63
HOST_TYPE_CIDR6_BLOCK
@ HOST_TYPE_CIDR6_BLOCK
Definition: hosts.h:44
gvm_hosts::current
size_t current
Definition: hosts.h:95
cidr_block_ips
static int cidr_block_ips(const char *str, struct in_addr *first, struct in_addr *last)
Gets the first and last usable IPv4 addresses from a CIDR-expressed block. eg. "192....
Definition: hosts.c:211
gvm_vhost::value
char * value
Definition: hosts.h:80
HOST_TYPE_RANGE_LONG
@ HOST_TYPE_RANGE_LONG
Definition: hosts.h:42
gvm_host::addr
struct in_addr addr
Definition: hosts.h:68
HOST_TYPE_RANGE6_LONG
@ HOST_TYPE_RANGE6_LONG
Definition: hosts.h:45
gvm_host_type
enum host_type gvm_host_type(const gvm_host_t *host)
Gets a host object's type.
Definition: hosts.c:1846
is_cidr_block
static int is_cidr_block(const char *str)
Checks if a buffer points to an IPv4 CIDR-expressed block. "192.168.12.3/24" is valid,...
Definition: hosts.c:104
gvm_hosts_exclude_with_max
int gvm_hosts_exclude_with_max(gvm_hosts_t *hosts, const char *excluded_str, unsigned int max_hosts)
Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating ...
Definition: hosts.c:1462
is_ipv4_address
static int is_ipv4_address(const char *str)
Checks if a buffer points to a valid IPv4 address. "192.168.11.1" is valid, "192.168....
Definition: hosts.c:72
gvm_host_new
static gvm_host_t * gvm_host_new()
Creates a new gvm_host_t object.
Definition: hosts.c:865
gvm_vhost::source
char * source
Definition: hosts.h:81
gvm_host_reverse_lookup
char * gvm_host_reverse_lookup(gvm_host_t *host)
Checks for a host object reverse dns lookup existence.
Definition: hosts.c:1549
HOST_TYPE_MAX
@ HOST_TYPE_MAX
Definition: hosts.h:47
is_short_range6_network
static int is_short_range6_network(const char *str)
Checks if a buffer points to a valid short IPv6 range-expressed network. "::200:ff:1-fee5" is valid.
Definition: hosts.c:677
gvm_vhost_free
static void gvm_vhost_free(gpointer vhost)
Frees the memory occupied by an gvm_vhost_t object.
Definition: hosts.c:849
gvm_hosts::orig_str
gchar * orig_str
Definition: hosts.h:92
host_name_verify
static int host_name_verify(gvm_host_t *host, const char *value)
Verifies that hostname value resolves to a host's IP.
Definition: hosts.c:1601
host_type
host_type
Definition: hosts.h:36
host_type_str
gchar * host_type_str[HOST_TYPE_MAX]
Definition: hosts.c:53
gvm_host::addr6
struct in6_addr addr6
Definition: hosts.h:69
gvm_vhost_new
gvm_vhost_t * gvm_vhost_new(char *value, char *source)
Creates a new gvm_vhost_t object.
Definition: hosts.c:832
HOST_TYPE_CIDR_BLOCK
@ HOST_TYPE_CIDR_BLOCK
Definition: hosts.h:40
gvm_hosts_fill_gaps
static void gvm_hosts_fill_gaps(gvm_hosts_t *hosts)
Fill the gaps in the array of a hosts collection, which are caused by the removal of host entries.
Definition: hosts.c:939
short_range_network_ips
static int short_range_network_ips(const char *str, struct in_addr *first, struct in_addr *last)
Gets the first and last IPv4 addresses from a short range-expressed network. "192....
Definition: hosts.c:362
HOST_TYPE_RANGE6_SHORT
@ HOST_TYPE_RANGE6_SHORT
Definition: hosts.h:46
gvm_hosts_deduplicate
static void gvm_hosts_deduplicate(gvm_hosts_t *hosts)
Removes duplicate hosts values from an gvm_hosts_t structure. Also resets the iterator current positi...
Definition: hosts.c:977
is_ipv6_address
static int is_ipv6_address(const char *str)
Checks if a buffer points to a valid IPv6 address. "0:0:0:0:0:0:0:1", "::1" and "::FFFF:192....
Definition: hosts.c:88
HOST_TYPE_NAME
@ HOST_TYPE_NAME
Definition: hosts.h:38
gvm_host_resolve
int gvm_host_resolve(const gvm_host_t *host, void *dst, int family)
Resolves a host object's name to an IPv4 or IPv6 address. Host object should be of type HOST_TYPE_NAM...
Definition: hosts.c:1934
gvm_host::vhosts
GSList * vhosts
Definition: hosts.h:72
gvm_hosts
The structure for Hosts collection.
Definition: hosts.h:90