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))
444 if (g_regex_match_simple (
"^(?!-)[a-z0-9_-]{1,63}(?<!-)$", *point,
470 char *addr6_str, *block_str, *p;
472 addr6_str = g_strdup (str);
473 block_str = strchr (addr6_str,
'/');
474 if (block_str == NULL)
491 block = strtol (block_str, &p, 10);
493 if (*p || block <= 0 || block > 128)
515 if (str == NULL || block == NULL)
518 if (sscanf (str,
"%*[0-9a-fA-F.:]/%3u", block) != 1)
536 gchar *addr6_str, *tmp;
538 if (str == NULL || addr6 == NULL)
541 addr6_str = g_strdup (str);
542 tmp = strchr (addr6_str,
'/');
550 if (inet_pton (AF_INET6, addr6_str, addr6) != 1)
574 if (str == NULL || first == NULL || last == NULL)
582 memcpy (&last->s6_addr, &first->s6_addr, 16);
590 for (i = (128 - block) / 8; i > 0; i--)
592 first->s6_addr[j] = 0;
595 first->s6_addr[j] &= 0xff ^ ((1 << ((128 - block) % 8)) - 1);
599 for (i = (128 - block) / 8; i > 0; i--)
601 last->s6_addr[j] = 0xff;
604 last->s6_addr[j] |= (1 << ((128 - block) % 8)) - 1;
611 for (i = 15; i >= 0; --i)
612 if (first->s6_addr[i] < 255)
618 first->s6_addr[i] = 0;
620 for (i = 15; i >= 0; --i)
621 if (last->s6_addr[i] > 0)
627 last->s6_addr[i] = 0xff;
643 char *first_str, *second_str;
646 first_str = g_strdup (str);
647 second_str = strchr (first_str,
'-');
648 if (second_str == NULL)
677 struct in6_addr *last)
679 char *first_str, *last_str;
681 if (str == NULL || first == NULL || last == NULL)
684 first_str = g_strdup (str);
685 last_str = strchr (first_str,
'-');
686 if (last_str == NULL)
696 if (inet_pton (AF_INET6, first_str, first) != 1
697 || inet_pton (AF_INET6, last_str, last) != 1)
718 char *ip_str, *end_str, *p;
720 ip_str = g_strdup (str);
721 end_str = strchr (ip_str,
'-');
740 while (isxdigit (*p) && p++)
742 if (*p || p - end_str > 4)
765 struct in6_addr *last)
767 char *first_str, *last_str;
770 if (str == NULL || first == NULL || last == NULL)
773 first_str = g_strdup (str);
774 last_str = strchr (first_str,
'-');
775 if (last_str == NULL)
785 if (inet_pton (AF_INET6, first_str, first) != 1)
792 memcpy (last, first,
sizeof (*last));
793 end = strtol (last_str, NULL, 16);
794 memcpy (&last->s6_addr[15], &end, 1);
795 memcpy (&last->s6_addr[14], ((
char *) &end) + 1, 1);
820 if (str_stripped == NULL || *str_stripped ==
'\0')
876 vhost->
value = value;
991 hosts->
orig_str = g_strdup (hosts_str);
1008 for (i = 0; i < hosts->
max_size; i++)
1010 if (!hosts->
hosts[i])
1016 for (j = i + 1; j < hosts->
max_size; j++)
1018 if (hosts->
hosts[j])
1021 hosts->
hosts[j] = NULL;
1027 if (!hosts->
hosts[i])
1045 GHashTable *name_table;
1046 size_t i, duplicates = 0;
1050 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1052 for (i = 0; i < hosts->
count; i++)
1060 host = g_hash_table_lookup (name_table, name);
1067 hosts->
hosts[i] = NULL;
1072 g_hash_table_insert (name_table, name, hosts->
hosts[i]);
1078 g_hash_table_destroy (name_table);
1079 hosts->
count -= duplicates;
1102 gchar **host_element, **split;
1105 if (hosts_str == NULL)
1119 split = g_strsplit (hosts->
orig_str,
",", 0);
1122 host_element = split;
1123 while (*host_element)
1126 gchar *stripped = g_strstrip (*host_element);
1128 if (stripped == NULL || *stripped ==
'\0')
1149 host->
name = g_ascii_strdown (stripped, -1);
1152 if (inet_pton (AF_INET, stripped, &host->
addr) != 1)
1157 if (inet_pton (AF_INET6, stripped, &host->
addr6) != 1)
1167 struct in_addr first, last;
1169 int (*ips_func) (
const char *,
struct in_addr *,
struct in_addr *);
1178 if (ips_func (stripped, &first, &last) == -1)
1182 if (ntohl (first.s_addr) > ntohl (last.s_addr))
1186 current = first.s_addr;
1187 while (ntohl (current) <= ntohl (last.s_addr))
1190 if (max_hosts > 0 && hosts->
count > max_hosts)
1198 host->
addr.s_addr = current;
1201 current = htonl (ntohl (current) + 1);
1209 struct in6_addr first, last;
1210 unsigned char current[16];
1211 int (*ips_func) (
const char *,
struct in6_addr *,
1221 if (ips_func (stripped, &first, &last) == -1)
1225 if (memcmp (&first.s6_addr, &last.s6_addr, 16) > 0)
1229 memcpy (current, &first.s6_addr, 16);
1230 while (memcmp (current, &last.s6_addr, 16) <= 0)
1235 if (max_hosts > 0 && hosts->
count > max_hosts)
1243 memcpy (host->
addr6.s6_addr, current, 16);
1246 for (i = 15; i >= 0; --i)
1247 if (current[i] < 255)
1265 if (max_hosts > 0 && hosts->
count > max_hosts)
1275 if (g_strv_length (split) > 1)
1345 for (i = hosts->
current; i < hosts->count; i++)
1367 for (i = 0; i < hosts->
count; i++)
1369 g_free (hosts->
hosts);
1391 rand = g_rand_new ();
1392 for (i = 0; i < hosts->
count; i++)
1395 int j = g_rand_int_range (rand, 0, hosts->
count);
1397 tmp = hosts->
hosts[i];
1399 hosts->
hosts[j] = tmp;
1420 for (i = 0, j = hosts->
count - 1; i < j; i++, j--)
1424 hosts->
hosts[j] = tmp;
1442 size_t i, new_entries = 0, resolved = 0;
1443 GSList *unresolved = NULL;
1445 for (i = 0; i < hosts->
count; i++)
1458 struct in6_addr *ip6 = tmp->data;
1462 if (ip6->s6_addr32[0] != 0 || ip6->s6_addr32[1] != 0
1463 || ip6->s6_addr32[2] != htonl (0xffff))
1466 memcpy (&new->addr6, ip6, sizeof (new->addr6));
1471 memcpy (&new->addr6, &ip6->s6_addr32[3], sizeof (new->addr));
1475 new->vhosts = g_slist_prepend (new->vhosts, vhost);
1482 hosts->
hosts[i] = NULL;
1485 unresolved = g_slist_prepend (unresolved, g_strdup (host->
name));
1487 g_slist_free_full (list, g_free);
1491 hosts->
count -= resolved;
1514 if (!host || !excluded_str)
1518 excluded = g_strsplit (excluded_str,
",", 0);
1519 if (!excluded || !*excluded)
1521 g_strfreev (excluded);
1526 char **tmp = excluded;
1527 char *value = ((
gvm_vhost_t *) vhost->data)->value;
1531 if (!strcasecmp (value, g_strstrip (*tmp)))
1534 host->
vhosts = vhost = g_slist_delete_link (host->
vhosts, vhost);
1541 vhost = vhost->next;
1546 g_strfreev (excluded);
1564 unsigned int max_hosts)
1570 GHashTable *name_table;
1571 size_t excluded = 0, i;
1573 if (hosts == NULL || excluded_str == NULL)
1577 if (excluded_hosts == NULL)
1587 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1588 for (i = 0; i < excluded_hosts->
count; i++)
1593 g_hash_table_insert (name_table, name, hosts);
1597 for (i = 0; i < hosts->
count; i++)
1603 if (g_hash_table_lookup (name_table, name))
1606 hosts->
hosts[i] = NULL;
1618 hosts->
count -= excluded;
1621 g_hash_table_destroy (name_table);
1640 const char *allow_hosts_str)
1646 GHashTable *name_allow_table = NULL, *name_deny_table = NULL;
1647 GSList *removed = NULL;
1648 size_t excluded = 0, i;
1650 if (hosts == NULL || (deny_hosts_str == NULL && allow_hosts_str == NULL))
1656 if (denied_hosts == NULL && allowed_hosts == NULL)
1665 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1666 for (i = 0; i < denied_hosts->
count; i++)
1671 g_hash_table_insert (name_deny_table, name, hosts);
1680 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1681 for (i = 0; i < allowed_hosts->
count; i++)
1686 g_hash_table_insert (name_allow_table, name, hosts);
1692 for (i = 0; i < hosts->
count; i++)
1698 if (denied_hosts != NULL
1699 && g_hash_table_lookup (name_deny_table, name))
1702 hosts->
hosts[i] = NULL;
1704 removed = g_slist_prepend (removed, name);
1707 else if (allowed_hosts != NULL
1708 && !g_hash_table_lookup (name_allow_table, name))
1711 hosts->
hosts[i] = NULL;
1713 removed = g_slist_prepend (removed, name);
1724 hosts->
count -= excluded;
1727 if (name_allow_table != NULL)
1728 g_hash_table_destroy (name_allow_table);
1729 if (name_deny_table != NULL)
1730 g_hash_table_destroy (name_deny_table);
1731 if (allowed_hosts != NULL)
1733 if (denied_hosts != NULL)
1769 if (host_str == NULL)
1786 host->
name = g_ascii_strdown (host_str, -1);
1789 if (inet_pton (AF_INET, host_str, &host->
addr) != 1)
1794 if (inet_pton (AF_INET6, host_str, &host->
addr6) != 1)
1817 gchar hostname[NI_MAXHOST];
1820 struct sockaddr_in sa;
1821 struct sockaddr_in6 sa6;
1829 addrlen =
sizeof (sa);
1830 memset (addr,
'\0', addrlen);
1831 sa.sin_addr = host->
addr;
1832 sa.sin_family = AF_INET;
1837 addrlen =
sizeof (sa6);
1838 memset (&sa6,
'\0', addrlen);
1839 memcpy (&sa6.sin6_addr, &host->
addr6, 16);
1840 sa6.sin6_family = AF_INET6;
1847 int ret = getnameinfo (addr, addrlen, hostname,
sizeof (hostname), NULL,
1850 return g_ascii_strdown (hostname, -1);
1851 if (ret != EAI_AGAIN)
1879 char buffer[INET6_ADDRSTRLEN];
1881 if (!strcasecmp (host_str, buffer))
1889 g_slist_free_full (list, g_free);
1920 if (!strcasecmp (((
gvm_vhost_t *) vhosts->data)->value, value))
1925 vhosts = vhosts->next;
1943 size_t i, count = 0;
1949 for (i = 0; i < hosts->
count; i++)
1957 hosts->
hosts[i] = NULL;
1966 hosts->
count -= count;
1991 count = excluded->
count;
2012 size_t i, count = 0;
2013 GHashTable *name_table;
2020 name_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
2021 for (i = 0; i < hosts->
count; i++)
2027 if (g_hash_table_lookup (name_table, name))
2031 hosts->
hosts[i] = NULL;
2038 g_hash_table_insert (name_table, name, hosts);
2045 g_hash_table_destroy (name_table);
2047 hosts->
count -= count;
2070 count = excluded->
count;
2085 return hosts ? hosts->
count : 0;
2099 return hosts ? hosts->
removed : 0;
2133 if (host == NULL || hosts == NULL)
2138 for (i = 0; i < hosts->
count; i++)
2143 if (strcasecmp (host_str, tmp) == 0)
2147 return current_host;
2154 struct in6_addr tmpaddr;
2157 if (memcmp (addr->s6_addr, &tmpaddr.s6_addr, 16) == 0)
2160 return current_host;
2275 return g_strdup (host->
name);
2283 const void *srcaddr;
2288 size = INET_ADDRSTRLEN;
2289 srcaddr = &host->
addr;
2294 size = INET6_ADDRSTRLEN;
2295 srcaddr = &host->
addr6;
2298 str = g_malloc0 (size);
2299 if (inet_ntop (family, srcaddr, str, size) == NULL)
2301 perror (
"inet_ntop");
2308 return g_strdup (
"Erroneous host type: Should be Hostname/IPv4/IPv6.");
2347 if (host == NULL || ip6 == NULL)
2353 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:962
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:2219
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:2007
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:1982
gchar * gvm_host_value_str(const gvm_host_t *host)
Gets a host's value in printable format.
Definition hosts.c:2267
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:2324
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:1941
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:641
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:1814
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:513
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:2176
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:871
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:1296
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:1310
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:1639
void gvm_host_free(gpointer host)
Frees the memory occupied by an gvm_host_t object.
Definition hosts.c:941
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:2097
gchar * gvm_host_type_str(const gvm_host_t *host)
Gets a host's type in printable format.
Definition hosts.c:2251
void gvm_host_add_reverse_lookup(gvm_host_t *host)
Add a host's reverse-lookup name to the vhosts list.
Definition hosts.c:1899
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:1099
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:467
static gvm_host_t * gvm_host_new()
Creates a new gvm_host_t object.
Definition hosts.c:926
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:1414
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:1382
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:2111
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:716
gvm_host_t * gvm_host_from_str(const gchar *host_str)
Creates a new gvm_host_t from a host string.
Definition hosts.c:1765
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:1040
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:764
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:569
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:984
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:676
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:2345
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:1328
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:1508
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:1563
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:1440
enum host_type gvm_host_type(const gvm_host_t *host)
Gets a host object's type.
Definition hosts.c:2236
gpointer gvm_duplicate_vhost(gconstpointer vhost, gpointer data)
Creates a deep copy of a gvm_vhost_t object.
Definition hosts.c:906
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:1002
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:1867
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:2127
int gvm_get_host_type(const gchar *str_stripped)
Determines the host type in a buffer.
Definition hosts.c:810
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:2083
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:888
void gvm_hosts_free(gvm_hosts_t *hosts)
Frees memory occupied by an gvm_hosts_t structure.
Definition hosts.c:1358
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:1749
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:2062
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:534
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
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.
The structure for a single host object.
Definition hosts.h:61
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
The structure for Hosts collection.
Definition hosts.h:88
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
The structure for a single vhost object.
Definition hosts.h:76
char * value
Definition hosts.h:77
char * source
Definition hosts.h:78