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)
573 struct in6_addr *last)
578 if (str == NULL || first == NULL || last == NULL)
586 memcpy (&last->s6_addr, &first->s6_addr, 16);
594 for (i = (128 - block) / 8; i > 0; i--)
596 first->s6_addr[j] = 0;
599 first->s6_addr[j] &= 0xff ^ ((1 << ((128 - block) % 8)) - 1);
603 for (i = (128 - block) / 8; i > 0; i--)
605 last->s6_addr[j] = 0xff;
608 last->s6_addr[j] |= (1 << ((128 - block) % 8)) - 1;
615 for (i = 15; i >= 0; --i)
616 if (first->s6_addr[i] < 255)
622 first->s6_addr[i] = 0;
624 for (i = 15; i >= 0; --i)
625 if (last->s6_addr[i] > 0)
631 last->s6_addr[i] = 0xff;
647 char *first_str, *second_str;
650 first_str = g_strdup (str);
651 second_str = strchr (first_str,
'-');
652 if (second_str == NULL)
681 struct in6_addr *last)
683 char *first_str, *last_str;
685 if (str == NULL || first == NULL || last == NULL)
688 first_str = g_strdup (str);
689 last_str = strchr (first_str,
'-');
690 if (last_str == NULL)
700 if (inet_pton (AF_INET6, first_str, first) != 1
701 || inet_pton (AF_INET6, last_str, last) != 1)
722 char *ip_str, *end_str, *p;
724 ip_str = g_strdup (str);
725 end_str = strchr (ip_str,
'-');
744 while (isxdigit (*p) && p++)
746 if (*p || p - end_str > 4)
769 struct in6_addr *last)
771 char *first_str, *last_str;
774 if (str == NULL || first == NULL || last == NULL)
777 first_str = g_strdup (str);
778 last_str = strchr (first_str,
'-');
779 if (last_str == NULL)
789 if (inet_pton (AF_INET6, first_str, first) != 1)
796 memcpy (last, first,
sizeof (*last));
797 end = strtol (last_str, NULL, 16);
798 memcpy (&last->s6_addr[15], &end, 1);
799 memcpy (&last->s6_addr[14], ((
char *) &end) + 1, 1);
824 if (str_stripped == NULL || *str_stripped ==
'\0')
880 vhost->
value = value;
995 hosts->
orig_str = g_strdup (hosts_str);
1012 for (i = 0; i < hosts->
max_size; i++)
1014 if (!hosts->
hosts[i])
1020 for (j = i + 1; j < hosts->
max_size; j++)
1022 if (hosts->
hosts[j])
1025 hosts->
hosts[j] = NULL;
1031 if (!hosts->
hosts[i])
1049 GHashTable *name_table;
1050 size_t i, duplicates = 0;
1054 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1056 for (i = 0; i < hosts->
count; i++)
1065 host = g_hash_table_lookup (name_table, name);
1072 hosts->
hosts[i] = NULL;
1077 g_hash_table_insert (name_table, name, hosts->
hosts[i]);
1083 g_hash_table_destroy (name_table);
1084 hosts->
count -= duplicates;
1107 gchar **host_element, **split;
1110 if (hosts_str == NULL)
1124 split = g_strsplit (hosts->
orig_str,
",", 0);
1127 host_element = split;
1128 while (*host_element)
1131 gchar *stripped = g_strstrip (*host_element);
1133 if (stripped == NULL || *stripped ==
'\0')
1154 host->
name = g_ascii_strdown (stripped, -1);
1157 if (inet_pton (AF_INET, stripped, &host->
addr) != 1)
1162 if (inet_pton (AF_INET6, stripped, &host->
addr6) != 1)
1172 struct in_addr first, last;
1174 int (*ips_func) (
const char *,
struct in_addr *,
struct in_addr *);
1183 if (ips_func (stripped, &first, &last) == -1)
1187 if (ntohl (first.s_addr) > ntohl (last.s_addr))
1191 current = first.s_addr;
1195 if (max_hosts > 0 && hosts->
count > max_hosts)
1203 host->
addr.s_addr = current;
1208 if (ntohl (current) >= ntohl (last.s_addr))
1211 current = htonl (ntohl (current) + 1);
1219 struct in6_addr first, last;
1220 unsigned char current[16];
1221 int (*ips_func) (
const char *,
struct in6_addr *,
1231 if (ips_func (stripped, &first, &last) == -1)
1235 if (memcmp (&first.s6_addr, &last.s6_addr, 16) > 0)
1239 memcpy (current, &first.s6_addr, 16);
1245 if (max_hosts > 0 && hosts->
count > max_hosts)
1253 memcpy (host->
addr6.s6_addr, current, 16);
1259 if (memcmp (current, &last.s6_addr, 16) >= 0)
1263 for (i = 15; i >= 0; --i)
1264 if (current[i] < 255)
1282 if (max_hosts > 0 && hosts->
count > max_hosts)
1292 if (g_strv_length (split) > 1)
1374 for (i = hosts->
current + 1; i < hosts->count; i++)
1396 for (i = 0; i < hosts->
count; i++)
1398 g_free (hosts->
hosts);
1420 rand = g_rand_new ();
1421 for (i = 0; i < hosts->
count; i++)
1424 int j = g_rand_int_range (rand, 0, hosts->
count);
1426 tmp = hosts->
hosts[i];
1428 hosts->
hosts[j] = tmp;
1446 if (hosts == NULL || hosts->
count < 2)
1449 for (i = 0, j = hosts->
count - 1; i < j; i++, j--)
1453 hosts->
hosts[j] = tmp;
1471 size_t i, new_entries = 0, resolved = 0;
1472 GSList *unresolved = NULL;
1474 for (i = 0; i < hosts->
count; i++)
1487 struct in6_addr *ip6 = tmp->data;
1491 if (ip6->s6_addr32[0] != 0 || ip6->s6_addr32[1] != 0
1492 || ip6->s6_addr32[2] != htonl (0xffff))
1495 memcpy (&new->addr6, ip6, sizeof (new->addr6));
1500 memcpy (&new->addr6, &ip6->s6_addr32[3], sizeof (new->addr));
1504 new->vhosts = g_slist_prepend (new->vhosts, vhost);
1511 hosts->
hosts[i] = NULL;
1514 unresolved = g_slist_prepend (unresolved, g_strdup (host->
name));
1516 g_slist_free_full (list, g_free);
1520 hosts->
count -= resolved;
1543 if (!host || !excluded_str)
1547 excluded = g_strsplit (excluded_str,
",", 0);
1548 if (!excluded || !*excluded)
1550 g_strfreev (excluded);
1555 char **tmp = excluded;
1556 char *value = ((
gvm_vhost_t *) vhost->data)->value;
1560 if (!strcasecmp (value, g_strstrip (*tmp)))
1563 host->
vhosts = vhost = g_slist_delete_link (host->
vhosts, vhost);
1570 vhost = vhost->next;
1575 g_strfreev (excluded);
1593 unsigned int max_hosts)
1599 GHashTable *name_table;
1600 size_t excluded = 0, i;
1602 if (hosts == NULL || excluded_str == NULL)
1606 if (excluded_hosts == NULL)
1616 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1617 for (i = 0; i < excluded_hosts->
count; i++)
1623 g_hash_table_insert (name_table, name, hosts);
1627 for (i = 0; i < hosts->
count; i++)
1634 if (g_hash_table_lookup (name_table, name))
1637 hosts->
hosts[i] = NULL;
1649 hosts->
count -= excluded;
1652 g_hash_table_destroy (name_table);
1671 const char *allow_hosts_str)
1677 GHashTable *name_allow_table = NULL, *name_deny_table = NULL;
1678 GSList *removed = NULL;
1679 size_t excluded = 0, i;
1681 if (hosts == NULL || (deny_hosts_str == NULL && allow_hosts_str == NULL))
1687 if (denied_hosts == NULL && allowed_hosts == NULL)
1696 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1697 for (i = 0; i < denied_hosts->
count; i++)
1703 g_hash_table_insert (name_deny_table, name, hosts);
1712 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1713 for (i = 0; i < allowed_hosts->
count; i++)
1719 g_hash_table_insert (name_allow_table, name, hosts);
1725 for (i = 0; i < hosts->
count; i++)
1732 if (denied_hosts != NULL
1733 && g_hash_table_lookup (name_deny_table, name))
1736 hosts->
hosts[i] = NULL;
1738 removed = g_slist_prepend (removed, name);
1741 else if (allowed_hosts != NULL
1742 && !g_hash_table_lookup (name_allow_table, name))
1745 hosts->
hosts[i] = NULL;
1747 removed = g_slist_prepend (removed, name);
1758 hosts->
count -= excluded;
1761 if (name_allow_table != NULL)
1762 g_hash_table_destroy (name_allow_table);
1763 if (name_deny_table != NULL)
1764 g_hash_table_destroy (name_deny_table);
1765 if (allowed_hosts != NULL)
1767 if (denied_hosts != NULL)
1803 if (host_str == NULL)
1820 host->
name = g_ascii_strdown (host_str, -1);
1823 if (inet_pton (AF_INET, host_str, &host->
addr) != 1)
1828 if (inet_pton (AF_INET6, host_str, &host->
addr6) != 1)
1851 gchar hostname[NI_MAXHOST];
1854 struct sockaddr_in sa;
1855 struct sockaddr_in6 sa6;
1863 addrlen =
sizeof (sa);
1864 memset (addr,
'\0', addrlen);
1865 sa.sin_addr = host->
addr;
1866 sa.sin_family = AF_INET;
1871 addrlen =
sizeof (sa6);
1872 memset (&sa6,
'\0', addrlen);
1873 memcpy (&sa6.sin6_addr, &host->
addr6, 16);
1874 sa6.sin6_family = AF_INET6;
1881 int ret = getnameinfo (addr, addrlen, hostname,
sizeof (hostname), NULL,
1884 return g_ascii_strdown (hostname, -1);
1885 if (ret != EAI_AGAIN)
1913 char buffer[INET6_ADDRSTRLEN];
1915 if (!strcasecmp (host_str, buffer))
1923 g_slist_free_full (list, g_free);
1954 if (!strcasecmp (((
gvm_vhost_t *) vhosts->data)->value, value))
1959 vhosts = vhosts->next;
1977 size_t i, count = 0;
1983 for (i = 0; i < hosts->
count; i++)
1991 hosts->
hosts[i] = NULL;
2000 hosts->
count -= count;
2025 count = excluded->
count;
2046 size_t i, count = 0;
2047 GHashTable *name_table;
2054 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
2055 for (i = 0; i < hosts->
count; i++)
2062 if (g_hash_table_lookup (name_table, name))
2066 hosts->
hosts[i] = NULL;
2073 g_hash_table_insert (name_table, name, hosts);
2080 g_hash_table_destroy (name_table);
2082 hosts->
count -= count;
2105 count = excluded->
count;
2120 return hosts ? hosts->
count : 0;
2134 return hosts ? hosts->
removed : 0;
2168 if (host == NULL || hosts == NULL)
2173 for (i = 0; i < hosts->
count; i++)
2178 if (strcasecmp (host_str, tmp) == 0)
2182 return current_host;
2189 struct in6_addr tmpaddr;
2192 if (memcmp (addr->s6_addr, &tmpaddr.s6_addr, 16) == 0)
2195 return current_host;
2310 return g_strdup (host->
name);
2318 const void *srcaddr;
2323 size = INET_ADDRSTRLEN;
2324 srcaddr = &host->
addr;
2329 size = INET6_ADDRSTRLEN;
2330 srcaddr = &host->
addr6;
2333 str = g_malloc0 (size);
2334 if (inet_ntop (family, srcaddr, str, size) == NULL)
2336 perror (
"inet_ntop");
2343 return g_strdup (
"Erroneous host type: Should be Hostname/IPv4/IPv6.");
2382 if (host == NULL || ip6 == NULL)
2388 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:966
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:2254
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:2041
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:2016
gchar * gvm_host_value_str(const gvm_host_t *host)
Gets a host's value in printable format.
Definition hosts.c:2302
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:2359
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:1975
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:645
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:1848
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
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:2211
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:875
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:1313
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:1327
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:1670
void gvm_host_free(gpointer host)
Frees the memory occupied by an gvm_host_t object.
Definition hosts.c:945
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:2132
gchar * gvm_host_type_str(const gvm_host_t *host)
Gets a host's type in printable format.
Definition hosts.c:2286
void gvm_host_add_reverse_lookup(gvm_host_t *host)
Add a host's reverse-lookup name to the vhosts list.
Definition hosts.c:1933
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:1104
int gvm_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_hostname(const char *str)
Checks if a buffer points to a valid hostname.
Definition hosts.c:396
static gvm_host_t * gvm_host_new()
Creates a new gvm_host_t object.
Definition hosts.c:930
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:1443
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:1411
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:2146
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:720
gvm_host_t * gvm_host_from_str(const gchar *host_str)
Creates a new gvm_host_t from a host string.
Definition hosts.c:1799
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:1044
int gvm_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
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:768
int gvm_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
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:988
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:680
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:2380
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:1345
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:1537
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:1592
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:1469
enum host_type gvm_host_type(const gvm_host_t *host)
Gets a host object's type.
Definition hosts.c:2271
gpointer gvm_duplicate_vhost(gconstpointer vhost, gpointer data)
Creates a deep copy of a gvm_vhost_t object.
Definition hosts.c:910
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:1006
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:1901
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:2162
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
Definition hosts.c:814
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:2118
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:892
void gvm_hosts_free(gvm_hosts_t *hosts)
Frees memory occupied by an gvm_hosts_t structure.
Definition hosts.c:1388
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:1783
int gvm_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
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:2097
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