29#include <sys/socket.h>
36#define G_LOG_DOMAIN "libgvm base"
61 struct sockaddr_in sa;
63 return inet_pton (AF_INET, str, &(sa.sin_addr)) == 1;
77 struct sockaddr_in6 sa6;
79 return inet_pton (AF_INET6, str, &(sa6.sin6_addr)) == 1;
94 char *addr_str, *block_str, *p;
96 addr_str = g_strdup (str);
97 block_str = strchr (addr_str,
'/');
98 if (block_str == NULL)
115 block = strtol (block_str, &p, 10);
117 if (*p || block <= 0 || block > 30)
139 if (str == NULL || block == NULL)
142 if (sscanf (str,
"%*[0-9.]/%2u", block) != 1)
160 gchar *addr_str, *tmp;
162 if (str == NULL || addr == NULL)
165 addr_str = g_strdup (str);
166 tmp = strchr (addr_str,
'/');
174 if (inet_pton (AF_INET, addr_str, addr) != 1)
202 if (str == NULL || first == NULL || last == NULL)
212 first->s_addr &= htonl (0xffffffff ^ ((1 << (32 - block)) - 1));
213 first->s_addr = htonl (ntohl (first->s_addr) + 1);
216 last->s_addr = htonl (ntohl (first->s_addr) + (1 << (32 - block)) - 3);
231 char *first_str, *second_str;
234 first_str = g_strdup (str);
235 second_str = strchr (first_str,
'-');
236 if (second_str == NULL)
265 struct in_addr *last)
267 char *first_str, *last_str;
269 if (str == NULL || first == NULL || last == NULL)
272 first_str = g_strdup (str);
273 last_str = strchr (first_str,
'-');
274 if (last_str == NULL)
284 if (inet_pton (AF_INET, first_str, first) != 1
285 || inet_pton (AF_INET, last_str, last) != 1)
307 char *ip_str, *end_str, *p;
309 ip_str = g_strdup (str);
310 end_str = strchr (ip_str,
'-');
328 end = strtol (end_str, &p, 10);
330 if (*p || end < 0 || end > 255)
353 struct in_addr *last)
355 char *first_str, *last_str;
358 if (str == NULL || first == NULL || last == NULL)
361 first_str = g_strdup (str);
362 last_str = strchr (first_str,
'-');
363 if (last_str == NULL)
372 end = atoi (last_str);
375 if (inet_pton (AF_INET, first_str, first) != 1)
382 last->s_addr = htonl ((ntohl (first->s_addr) & 0xffffff00) + end);
398 gchar *copy, **point, **split;
405 copy = g_strdup (str);
406 if (copy[strlen (copy) - 1] ==
'.')
407 copy[strlen (copy) - 1] =
'\0';
411 if (strlen (copy) == 0 || strlen (copy) > 253)
419 point = split = g_strsplit (copy,
".", 0);
433 while (*last && isdigit (*last))
447 if (g_regex_match_simple (
"^(?!-)[a-z0-9_-]{1,63}(?<!-)$", *point,
473 char *addr6_str, *block_str, *p;
475 addr6_str = g_strdup (str);
476 block_str = strchr (addr6_str,
'/');
477 if (block_str == NULL)
494 block = strtol (block_str, &p, 10);
496 if (*p || block <= 0 || block > 128)
518 if (str == NULL || block == NULL)
521 if (sscanf (str,
"%*[0-9a-fA-F.:]/%3u", block) != 1)
539 gchar *addr6_str, *tmp;
541 if (str == NULL || addr6 == NULL)
544 addr6_str = g_strdup (str);
545 tmp = strchr (addr6_str,
'/');
553 if (inet_pton (AF_INET6, addr6_str, addr6) != 1)
577 if (str == NULL || first == NULL || last == NULL)
585 memcpy (&last->s6_addr, &first->s6_addr, 16);
593 for (i = (128 - block) / 8; i > 0; i--)
595 first->s6_addr[j] = 0;
598 first->s6_addr[j] &= 0xff ^ ((1 << ((128 - block) % 8)) - 1);
602 for (i = (128 - block) / 8; i > 0; i--)
604 last->s6_addr[j] = 0xff;
607 last->s6_addr[j] |= (1 << ((128 - block) % 8)) - 1;
614 for (i = 15; i >= 0; --i)
615 if (first->s6_addr[i] < 255)
621 first->s6_addr[i] = 0;
623 for (i = 15; i >= 0; --i)
624 if (last->s6_addr[i] > 0)
630 last->s6_addr[i] = 0xff;
646 char *first_str, *second_str;
649 first_str = g_strdup (str);
650 second_str = strchr (first_str,
'-');
651 if (second_str == NULL)
680 struct in6_addr *last)
682 char *first_str, *last_str;
684 if (str == NULL || first == NULL || last == NULL)
687 first_str = g_strdup (str);
688 last_str = strchr (first_str,
'-');
689 if (last_str == NULL)
699 if (inet_pton (AF_INET6, first_str, first) != 1
700 || inet_pton (AF_INET6, last_str, last) != 1)
721 char *ip_str, *end_str, *p;
723 ip_str = g_strdup (str);
724 end_str = strchr (ip_str,
'-');
743 while (isxdigit (*p) && p++)
745 if (*p || p - end_str > 4)
768 struct in6_addr *last)
770 char *first_str, *last_str;
773 if (str == NULL || first == NULL || last == NULL)
776 first_str = g_strdup (str);
777 last_str = strchr (first_str,
'-');
778 if (last_str == NULL)
788 if (inet_pton (AF_INET6, first_str, first) != 1)
795 memcpy (last, first,
sizeof (*last));
796 end = strtol (last_str, NULL, 16);
797 memcpy (&last->s6_addr[15], &end, 1);
798 memcpy (&last->s6_addr[14], ((
char *) &end) + 1, 1);
823 if (str_stripped == NULL || *str_stripped ==
'\0')
879 vhost->
value = value;
994 hosts->
orig_str = g_strdup (hosts_str);
1011 for (i = 0; i < hosts->
max_size; i++)
1013 if (!hosts->
hosts[i])
1019 for (j = i + 1; j < hosts->
max_size; j++)
1021 if (hosts->
hosts[j])
1024 hosts->
hosts[j] = NULL;
1030 if (!hosts->
hosts[i])
1048 GHashTable *name_table;
1049 size_t i, duplicates = 0;
1053 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1055 for (i = 0; i < hosts->
count; i++)
1064 host = g_hash_table_lookup (name_table, name);
1071 hosts->
hosts[i] = NULL;
1076 g_hash_table_insert (name_table, name, hosts->
hosts[i]);
1082 g_hash_table_destroy (name_table);
1083 hosts->
count -= duplicates;
1106 gchar **host_element, **split;
1109 if (hosts_str == NULL)
1123 split = g_strsplit (hosts->
orig_str,
",", 0);
1126 host_element = split;
1127 while (*host_element)
1130 gchar *stripped = g_strstrip (*host_element);
1132 if (stripped == NULL || *stripped ==
'\0')
1153 host->
name = g_ascii_strdown (stripped, -1);
1156 if (inet_pton (AF_INET, stripped, &host->
addr) != 1)
1161 if (inet_pton (AF_INET6, stripped, &host->
addr6) != 1)
1171 struct in_addr first, last;
1173 int (*ips_func) (
const char *,
struct in_addr *,
struct in_addr *);
1182 if (ips_func (stripped, &first, &last) == -1)
1186 if (ntohl (first.s_addr) > ntohl (last.s_addr))
1190 current = first.s_addr;
1191 while (ntohl (current) <= ntohl (last.s_addr))
1194 if (max_hosts > 0 && hosts->
count > max_hosts)
1202 host->
addr.s_addr = current;
1205 current = htonl (ntohl (current) + 1);
1213 struct in6_addr first, last;
1214 unsigned char current[16];
1215 int (*ips_func) (
const char *,
struct in6_addr *,
1225 if (ips_func (stripped, &first, &last) == -1)
1229 if (memcmp (&first.s6_addr, &last.s6_addr, 16) > 0)
1233 memcpy (current, &first.s6_addr, 16);
1234 while (memcmp (current, &last.s6_addr, 16) <= 0)
1239 if (max_hosts > 0 && hosts->
count > max_hosts)
1247 memcpy (host->
addr6.s6_addr, current, 16);
1250 for (i = 15; i >= 0; --i)
1251 if (current[i] < 255)
1269 if (max_hosts > 0 && hosts->
count > max_hosts)
1279 if (g_strv_length (split) > 1)
1361 for (i = hosts->
current + 1; i < hosts->count; i++)
1383 for (i = 0; i < hosts->
count; i++)
1385 g_free (hosts->
hosts);
1407 rand = g_rand_new ();
1408 for (i = 0; i < hosts->
count; i++)
1411 int j = g_rand_int_range (rand, 0, hosts->
count);
1413 tmp = hosts->
hosts[i];
1415 hosts->
hosts[j] = tmp;
1436 for (i = 0, j = hosts->
count - 1; i < j; i++, j--)
1440 hosts->
hosts[j] = tmp;
1458 size_t i, new_entries = 0, resolved = 0;
1459 GSList *unresolved = NULL;
1461 for (i = 0; i < hosts->
count; i++)
1474 struct in6_addr *ip6 = tmp->data;
1478 if (ip6->s6_addr32[0] != 0 || ip6->s6_addr32[1] != 0
1479 || ip6->s6_addr32[2] != htonl (0xffff))
1482 memcpy (&new->addr6, ip6, sizeof (new->addr6));
1487 memcpy (&new->addr6, &ip6->s6_addr32[3], sizeof (new->addr));
1491 new->vhosts = g_slist_prepend (new->vhosts, vhost);
1498 hosts->
hosts[i] = NULL;
1501 unresolved = g_slist_prepend (unresolved, g_strdup (host->
name));
1503 g_slist_free_full (list, g_free);
1507 hosts->
count -= resolved;
1530 if (!host || !excluded_str)
1534 excluded = g_strsplit (excluded_str,
",", 0);
1535 if (!excluded || !*excluded)
1537 g_strfreev (excluded);
1542 char **tmp = excluded;
1543 char *value = ((
gvm_vhost_t *) vhost->data)->value;
1547 if (!strcasecmp (value, g_strstrip (*tmp)))
1550 host->
vhosts = vhost = g_slist_delete_link (host->
vhosts, vhost);
1557 vhost = vhost->next;
1562 g_strfreev (excluded);
1580 unsigned int max_hosts)
1586 GHashTable *name_table;
1587 size_t excluded = 0, i;
1589 if (hosts == NULL || excluded_str == NULL)
1593 if (excluded_hosts == NULL)
1603 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1604 for (i = 0; i < excluded_hosts->
count; i++)
1610 g_hash_table_insert (name_table, name, hosts);
1614 for (i = 0; i < hosts->
count; i++)
1621 if (g_hash_table_lookup (name_table, name))
1624 hosts->
hosts[i] = NULL;
1636 hosts->
count -= excluded;
1639 g_hash_table_destroy (name_table);
1658 const char *allow_hosts_str)
1664 GHashTable *name_allow_table = NULL, *name_deny_table = NULL;
1665 GSList *removed = NULL;
1666 size_t excluded = 0, i;
1668 if (hosts == NULL || (deny_hosts_str == NULL && allow_hosts_str == NULL))
1674 if (denied_hosts == NULL && allowed_hosts == NULL)
1683 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1684 for (i = 0; i < denied_hosts->
count; i++)
1690 g_hash_table_insert (name_deny_table, name, hosts);
1699 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1700 for (i = 0; i < allowed_hosts->
count; i++)
1706 g_hash_table_insert (name_allow_table, name, hosts);
1712 for (i = 0; i < hosts->
count; i++)
1719 if (denied_hosts != NULL
1720 && g_hash_table_lookup (name_deny_table, name))
1723 hosts->
hosts[i] = NULL;
1725 removed = g_slist_prepend (removed, name);
1728 else if (allowed_hosts != NULL
1729 && !g_hash_table_lookup (name_allow_table, name))
1732 hosts->
hosts[i] = NULL;
1734 removed = g_slist_prepend (removed, name);
1745 hosts->
count -= excluded;
1748 if (name_allow_table != NULL)
1749 g_hash_table_destroy (name_allow_table);
1750 if (name_deny_table != NULL)
1751 g_hash_table_destroy (name_deny_table);
1752 if (allowed_hosts != NULL)
1754 if (denied_hosts != NULL)
1790 if (host_str == NULL)
1807 host->
name = g_ascii_strdown (host_str, -1);
1810 if (inet_pton (AF_INET, host_str, &host->
addr) != 1)
1815 if (inet_pton (AF_INET6, host_str, &host->
addr6) != 1)
1838 gchar hostname[NI_MAXHOST];
1841 struct sockaddr_in sa;
1842 struct sockaddr_in6 sa6;
1850 addrlen =
sizeof (sa);
1851 memset (addr,
'\0', addrlen);
1852 sa.sin_addr = host->
addr;
1853 sa.sin_family = AF_INET;
1858 addrlen =
sizeof (sa6);
1859 memset (&sa6,
'\0', addrlen);
1860 memcpy (&sa6.sin6_addr, &host->
addr6, 16);
1861 sa6.sin6_family = AF_INET6;
1868 int ret = getnameinfo (addr, addrlen, hostname,
sizeof (hostname), NULL,
1871 return g_ascii_strdown (hostname, -1);
1872 if (ret != EAI_AGAIN)
1900 char buffer[INET6_ADDRSTRLEN];
1902 if (!strcasecmp (host_str, buffer))
1910 g_slist_free_full (list, g_free);
1941 if (!strcasecmp (((
gvm_vhost_t *) vhosts->data)->value, value))
1946 vhosts = vhosts->next;
1964 size_t i, count = 0;
1970 for (i = 0; i < hosts->
count; i++)
1978 hosts->
hosts[i] = NULL;
1987 hosts->
count -= count;
2012 count = excluded->
count;
2033 size_t i, count = 0;
2034 GHashTable *name_table;
2041 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
2042 for (i = 0; i < hosts->
count; i++)
2049 if (g_hash_table_lookup (name_table, name))
2053 hosts->
hosts[i] = NULL;
2060 g_hash_table_insert (name_table, name, hosts);
2067 g_hash_table_destroy (name_table);
2069 hosts->
count -= count;
2092 count = excluded->
count;
2107 return hosts ? hosts->
count : 0;
2121 return hosts ? hosts->
removed : 0;
2155 if (host == NULL || hosts == NULL)
2160 for (i = 0; i < hosts->
count; i++)
2165 if (strcasecmp (host_str, tmp) == 0)
2169 return current_host;
2176 struct in6_addr tmpaddr;
2179 if (memcmp (addr->s6_addr, &tmpaddr.s6_addr, 16) == 0)
2182 return current_host;
2214 ret->
addr.s_addr = host->
addr.s_addr;
2297 return g_strdup (host->
name);
2305 const void *srcaddr;
2310 size = INET_ADDRSTRLEN;
2311 srcaddr = &host->
addr;
2316 size = INET6_ADDRSTRLEN;
2317 srcaddr = &host->
addr6;
2320 str = g_malloc0 (size);
2321 if (inet_ntop (family, srcaddr, str, size) == NULL)
2323 perror (
"inet_ntop");
2330 return g_strdup (
"Erroneous host type: Should be Hostname/IPv4/IPv6.");
2369 if (host == NULL || ip6 == NULL)
2375 memcpy (ip6, &host->
addr6, sizeof (
struct in6_addr));
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:965
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...
Definition hosts.c:2241
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:229
gvm_hosts_t * gvm_hosts_reverse_lookup_unify_excluded(gvm_hosts_t *hosts)
Removes hosts duplicates that reverse-lookup to the same value. Not to be used while iterating over t...
Definition hosts.c:2028
static int cidr_get_ip(const char *str, struct in_addr *addr)
Gets the IPv4 value from a CIDR-expressed block. eg. For "192.168.1.10/24" it is "192....
Definition hosts.c:158
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 ove...
Definition hosts.c:2003
gchar * gvm_host_value_str(const gvm_host_t *host)
Gets a host's value in printable format.
Definition hosts.c:2289
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:352
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:2346
gvm_hosts_t * gvm_hosts_reverse_lookup_only_excluded(gvm_hosts_t *hosts)
Removes hosts that don't reverse-lookup from the hosts collection. Not to be used while iterating ove...
Definition hosts.c:1962
gchar * host_type_str[HOST_TYPE_MAX]
Definition hosts.c:40
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:644
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:264
char * gvm_host_reverse_lookup(gvm_host_t *host)
Checks for a host object reverse dns lookup existence.
Definition hosts.c:1835
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:91
static int cidr6_get_block(const char *str, unsigned int *block)
Gets the network block value from a CIDR-expressed block string. For "192.168.1.1/24" it is 24.
Definition hosts.c:516
gvm_host_t * gvm_duplicate_host(gvm_host_t *host)
Creates a deep copy of a host. gvm_host_free has to be called on it.
Definition hosts.c:2198
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:304
gvm_vhost_t * gvm_vhost_new(char *value, char *source)
Creates a new gvm_vhost_t object.
Definition hosts.c:874
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.
Definition hosts.c:1300
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 with...
Definition hosts.c:1314
GSList * gvm_hosts_allowed_only(gvm_hosts_t *hosts, const char *deny_hosts_str, const char *allow_hosts_str)
Returns a list of hosts after a host authorization check.
Definition hosts.c:1657
void gvm_host_free(gpointer host)
Frees the memory occupied by an gvm_host_t object.
Definition hosts.c:944
unsigned int gvm_hosts_removed(const gvm_hosts_t *hosts)
Gets the count of single values in hosts string that were removed (duplicates / excluded....
Definition hosts.c:2119
gchar * gvm_host_type_str(const gvm_host_t *host)
Gets a host's type in printable format.
Definition hosts.c:2273
void gvm_host_add_reverse_lookup(gvm_host_t *host)
Add a host's reverse-lookup name to the vhosts list.
Definition hosts.c:1920
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:1103
static int is_hostname(const char *str)
Checks if a buffer points to a valid hostname.
Definition hosts.c:396
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:470
static gvm_host_t * gvm_host_new()
Creates a new gvm_host_t object.
Definition hosts.c:929
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 si...
Definition hosts.c:1430
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 ...
Definition hosts.c:1398
unsigned int gvm_hosts_duplicated(const gvm_hosts_t *hosts)
Gets the count of single values in hosts string that were duplicated and therefore removed from the l...
Definition hosts.c:2133
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:719
gvm_host_t * gvm_host_from_str(const gchar *host_str)
Creates a new gvm_host_t from a host string.
Definition hosts.c:1786
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:1043
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:767
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:572
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:75
static gvm_hosts_t * gvm_hosts_init(const char *hosts_str)
Creates a hosts collection from a hosts string.
Definition hosts.c:987
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:679
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:2367
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:59
void gvm_hosts_move_current_host_to_end(gvm_hosts_t *hosts)
Move the current gvm_host_t from a gvm_hosts_t structure to the end of the hosts list.
Definition hosts.c:1332
int gvm_vhosts_exclude(gvm_host_t *host, const char *excluded_str)
Exclude a list of vhosts from a host's vhosts list.
Definition hosts.c:1524
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:1579
GSList * gvm_hosts_resolve(gvm_hosts_t *hosts)
Resolves host objects of type name in a hosts collection, replacing hostnames with IPv4 values....
Definition hosts.c:1456
enum host_type gvm_host_type(const gvm_host_t *host)
Gets a host object's type.
Definition hosts.c:2258
gpointer gvm_duplicate_vhost(gconstpointer vhost, gpointer data)
Creates a deep copy of a gvm_vhost_t object.
Definition hosts.c:909
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:1005
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:1888
gvm_host_t * gvm_host_find_in_hosts(const gvm_host_t *host, const struct in6_addr *addr, const gvm_hosts_t *hosts)
Find the gvm_host_t from a gvm_hosts_t structure.
Definition hosts.c:2149
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
Definition hosts.c:813
static int cidr_get_block(const char *str, unsigned int *block)
Gets the network block value from a CIDR-expressed block string. For "192.168.1.1/24" it is 24.
Definition hosts.c:137
unsigned int gvm_hosts_count(const gvm_hosts_t *hosts)
Gets the count of single hosts objects in a hosts collection.
Definition hosts.c:2105
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:198
static void gvm_vhost_free(gpointer vhost)
Frees the memory occupied by an gvm_vhost_t object.
Definition hosts.c:891
void gvm_hosts_free(gvm_hosts_t *hosts)
Frees memory occupied by an gvm_hosts_t structure.
Definition hosts.c:1375
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 ...
Definition hosts.c:1770
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 t...
Definition hosts.c:2084
static int cidr6_get_ip(const char *str, struct in6_addr *addr6)
Gets the IPv4 value from a CIDR-expressed block. eg. For "192.168.1.10/24" it is "192....
Definition hosts.c:537
Protos and data structures for Hosts collections and single hosts objects.
host_type
Definition hosts.h:34
@ HOST_TYPE_RANGE_SHORT
Definition hosts.h:38
@ HOST_TYPE_RANGE6_SHORT
Definition hosts.h:43
@ HOST_TYPE_RANGE_LONG
Definition hosts.h:39
@ HOST_TYPE_RANGE6_LONG
Definition hosts.h:42
@ HOST_TYPE_NAME
Definition hosts.h:35
@ HOST_TYPE_IPV6
Definition hosts.h:40
@ HOST_TYPE_CIDR6_BLOCK
Definition hosts.h:41
@ HOST_TYPE_MAX
Definition hosts.h:44
@ HOST_TYPE_IPV4
Definition hosts.h:36
@ HOST_TYPE_CIDR_BLOCK
Definition hosts.h:37
struct gvm_host gvm_host_t
Definition hosts.h:48
struct gvm_vhost gvm_vhost_t
Definition hosts.h:49
struct gvm_hosts gvm_hosts_t
Definition hosts.h:50
void addr6_to_str(const struct in6_addr *addr6, char *str)
Stringifies an IP address.
Definition networking.c:261
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:243
int gvm_resolve(const char *name, void *dst, int family)
Resolves a hostname to an IPv4 or IPv6 address.
Definition networking.c:389
GSList * gvm_resolve_list(const char *name)
Returns a list of addresses that a hostname resolves to.
Definition networking.c:339
GVM Networking related API.
struct in6_addr addr6
Definition hosts.h:66
gchar * name
Definition hosts.h:64
GSList * vhosts
Definition hosts.h:69
struct in_addr addr
Definition hosts.h:65
enum host_type type
Definition hosts.h:68
size_t max_size
Definition hosts.h:91
size_t removed
Definition hosts.h:94
gchar * orig_str
Definition hosts.h:89
size_t duplicated
Definition hosts.h:95
size_t current
Definition hosts.h:92
size_t count
Definition hosts.h:93
gvm_host_t ** hosts
Definition hosts.h:90
char * value
Definition hosts.h:77
char * source
Definition hosts.h:78