Greenbone Vulnerability Management Libraries
10.0.0
|
Implementation of an API to handle Hosts objects. More...
#include "hosts.h"
#include "networking.h"
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <malloc.h>
#include <netdb.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
Go to the source code of this file.
Macros | |
#define | G_LOG_DOMAIN "base hosts" |
GLib log domain. More... | |
Functions | |
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.1.300" and "192.168.1.1e" are not. More... | |
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.168.13.55" are valid "::1g" is not. More... | |
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, "192.168.1.3/31" is not. More... | |
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. More... | |
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.168.1.10". More... | |
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.168.1.0/24" would give 192.168.1.1 as first and 192.168.1.254 as last. More... | |
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.168.13.50" is valid. More... | |
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.168.1.1-192.168.2.40" would give 192.168.1.1 as first and 192.168.2.40 as last. More... | |
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, "192.168.1.1-50e" and "192.168.1.1-300" are not. More... | |
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.168.1.1-40" would give 192.168.1.1 as first and 192.168.1.40 as last. More... | |
static int | is_hostname (const char *str) |
Checks if a buffer points to a valid hostname. Valid characters include: Alphanumerics, dot (.), dash (-) and underscore (_) up to 255 characters. More... | |
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, "2620:0:2d0:200::7/129" is not. More... | |
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. More... | |
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.168.1.10". More... | |
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.168.1.0/24 would give 192.168.1.1 as first and 192.168.1.254 as last. Thus, it skips the network and broadcast addresses. More... | |
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. More... | |
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:500" would give ::1:200:7 as first and ::1:205:500 as last. More... | |
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. More... | |
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" would give ::ffee:1:1001 as first and ::ffee:1:1005 as last. More... | |
int | gvm_get_host_type (const gchar *str_stripped) |
Determines the host type in a buffer. More... | |
gvm_vhost_t * | gvm_vhost_new (char *value, char *source) |
Creates a new gvm_vhost_t object. More... | |
static void | gvm_vhost_free (gpointer vhost) |
Frees the memory occupied by an gvm_vhost_t object. More... | |
static gvm_host_t * | gvm_host_new () |
Creates a new gvm_host_t object. More... | |
static void | gvm_host_free (gpointer host) |
Frees the memory occupied by an gvm_host_t object. More... | |
static void | gvm_hosts_add (gvm_hosts_t *hosts, gvm_host_t *host) |
Inserts a host object at the end of a hosts collection. More... | |
static gvm_hosts_t * | gvm_hosts_init (const char *hosts_str) |
Creates a hosts collection from a hosts string. More... | |
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. More... | |
static void | gvm_hosts_deduplicate (gvm_hosts_t *hosts) |
Removes duplicate hosts values from an gvm_hosts_t structure. Also resets the iterator current position. More... | |
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. More... | |
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. More... | |
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. More... | |
void | gvm_hosts_free (gvm_hosts_t *hosts) |
Frees memory occupied by an gvm_hosts_t structure. More... | |
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. More... | |
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. More... | |
void | 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. More... | |
int | gvm_vhosts_exclude (gvm_host_t *host, const char *excluded_str) |
Exclude a list of vhosts from a host's vhosts list. More... | |
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. More... | |
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. More... | |
char * | gvm_host_reverse_lookup (gvm_host_t *host) |
Checks for a host object reverse dns lookup existence. More... | |
static int | host_name_verify (gvm_host_t *host, const char *value) |
Verifies that hostname value resolves to a host's IP. More... | |
void | gvm_host_add_reverse_lookup (gvm_host_t *host) |
Add a host's reverse-lookup name to the vhosts list. More... | |
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. More... | |
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. More... | |
unsigned int | gvm_hosts_count (const gvm_hosts_t *hosts) |
Gets the count of single hosts objects in a hosts collection. More... | |
unsigned int | gvm_hosts_removed (const gvm_hosts_t *hosts) |
Gets the count of single values in hosts string that were removed (duplicates / excluded.) More... | |
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. More... | |
enum host_type | gvm_host_type (const gvm_host_t *host) |
Gets a host object's type. More... | |
gchar * | gvm_host_type_str (const gvm_host_t *host) |
Gets a host's type in printable format. More... | |
gchar * | gvm_host_value_str (const gvm_host_t *host) |
Gets a host's value in printable format. More... | |
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. More... | |
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. More... | |
Variables | |
gchar * | host_type_str [HOST_TYPE_MAX] |
Implementation of an API to handle Hosts objects.
This file contains all methods to handle Hosts collections (gvm_hosts_t) and single hosts objects (gvm_host_t.)
The module consequently uses glib datatypes.
Definition in file hosts.c.
|
static |
Gets the first and last usable IPv4 addresses from a CIDR-expressed block. eg. "192.168.1.0/24 would give 192.168.1.1 as first and 192.168.1.254 as last. Thus, it skips the network and broadcast addresses.
[in] | str | Buffer containing CIDR-expressed block. |
[out] | first | First IPv4 address in block. |
[out] | last | Last IPv4 address in block. |
Definition at line 527 of file hosts.c.
References cidr6_get_block(), and cidr6_get_ip().
Referenced by gvm_hosts_new_with_max().
|
static |
Gets the network block value from a CIDR-expressed block string. For "192.168.1.1/24" it is 24.
[in] | str | Buffer containing CIDR-expressed block. |
[out] | block | Variable to store block value. |
Definition at line 471 of file hosts.c.
Referenced by cidr6_block_ips().
|
static |
Gets the IPv4 value from a CIDR-expressed block. eg. For "192.168.1.10/24" it is "192.168.1.10".
[in] | str | String containing CIDR-expressed block. |
[out] | addr6 | Variable to store the IPv4 address value. |
Definition at line 492 of file hosts.c.
Referenced by cidr6_block_ips().
|
static |
Gets the first and last usable IPv4 addresses from a CIDR-expressed block. eg. "192.168.1.0/24" would give 192.168.1.1 as first and 192.168.1.254 as last.
Both network and broadcast addresses are skipped:
[in] | str | Buffer containing CIDR-expressed block. |
[out] | first | First IPv4 address in block. |
[out] | last | Last IPv4 address in block. |
Definition at line 208 of file hosts.c.
References cidr_get_block(), and cidr_get_ip().
Referenced by gvm_hosts_new_with_max().
|
static |
Gets the network block value from a CIDR-expressed block string. For "192.168.1.1/24" it is 24.
[in] | str | Buffer containing CIDR-expressed block. |
[out] | block | Variable to store block value. |
Definition at line 147 of file hosts.c.
Referenced by cidr_block_ips().
|
static |
Gets the IPv4 value from a CIDR-expressed block. eg. For "192.168.1.10/24" it is "192.168.1.10".
[in] | str | String containing CIDR-expressed block. |
[out] | addr | Variable to store the IPv4 address value. |
Definition at line 168 of file hosts.c.
Referenced by cidr_block_ips().
int gvm_get_host_type | ( | const gchar * | str_stripped | ) |
Determines the host type in a buffer.
[in] | str_stripped | Buffer that contains host definition, could a be hostname, single IPv4 or IPv6, CIDR-expressed block etc,. |
Definition at line 768 of file hosts.c.
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().
void gvm_host_add_reverse_lookup | ( | gvm_host_t * | host | ) |
Add a host's reverse-lookup name to the vhosts list.
[in] | host | The host to which we add the vhost. |
Definition at line 1628 of file hosts.c.
References gvm_host_reverse_lookup(), gvm_vhost_new(), host_name_verify(), HOST_TYPE_NAME, gvm_host::type, and gvm_host::vhosts.
|
static |
Frees the memory occupied by an gvm_host_t object.
[in] | host | Host to free. |
Definition at line 877 of file hosts.c.
References gvm_vhost_free(), HOST_TYPE_NAME, gvm_host::name, gvm_host::type, and gvm_host::vhosts.
Referenced by gvm_hosts_deduplicate(), gvm_hosts_exclude_with_max(), gvm_hosts_free(), gvm_hosts_resolve(), gvm_hosts_reverse_lookup_only(), and gvm_hosts_reverse_lookup_unify().
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.
[in] | host | The host object whose value to get as IPv6. |
[out] | ip6 | Buffer to store the IPv6 address. |
Definition at line 1950 of file hosts.c.
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().
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.
[in] | host | The host object. |
[in] | addr | Optional pointer to ip address. Could be used so that host isn't resolved multiple times when type is HOST_TYPE_NAME. |
[in] | hosts | Hosts collection. |
Definition at line 1791 of file hosts.c.
References gvm_hosts::count, gvm_host_get_addr6(), gvm_host_type(), gvm_host_value_str(), HOST_TYPE_NAME, and gvm_hosts::hosts.
|
static |
Creates a new gvm_host_t object.
Definition at line 862 of file hosts.c.
Referenced by gvm_hosts_new_with_max(), and gvm_hosts_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.
[in] | host | The host object whose name to resolve. |
[out] | dst | Buffer to store resolved address. Size must be at least 4 bytes for AF_INET and 16 bytes for AF_INET6. |
[in] | family | Either AF_INET or AF_INET6. |
Definition at line 1929 of file hosts.c.
References gvm_resolve(), HOST_TYPE_NAME, gvm_host::name, and gvm_host::type.
Referenced by gvm_host_get_addr6().
char* gvm_host_reverse_lookup | ( | gvm_host_t * | host | ) |
Checks for a host object reverse dns lookup existence.
[in] | host | The host to reverse-lookup. |
Definition at line 1541 of file hosts.c.
References gvm_host::addr, gvm_host::addr6, HOST_TYPE_IPV4, HOST_TYPE_IPV6, HOST_TYPE_NAME, and gvm_host::type.
Referenced by gvm_host_add_reverse_lookup(), gvm_hosts_reverse_lookup_only(), and gvm_hosts_reverse_lookup_unify().
enum host_type gvm_host_type | ( | const gvm_host_t * | host | ) |
Gets a host object's type.
[in] | host | The host object. |
Definition at line 1841 of file hosts.c.
References gvm_host::type.
Referenced by gvm_host_get_addr6(), and gvm_host_in_hosts().
gchar* gvm_host_type_str | ( | const gvm_host_t * | host | ) |
Gets a host's type in printable format.
[in] | host | The host object. |
Definition at line 1856 of file hosts.c.
References host_type_str, and gvm_host::type.
gchar* gvm_host_value_str | ( | const gvm_host_t * | host | ) |
Gets a host's value in printable format.
[in] | host | The host object. |
Definition at line 1872 of file hosts.c.
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().
|
static |
Inserts a host object at the end of a hosts collection.
[in] | hosts | Hosts in which to insert the host. |
[in] | host | Host to insert. |
Definition at line 898 of file hosts.c.
References gvm_hosts::count, gvm_hosts::hosts, and gvm_hosts::max_size.
Referenced by gvm_hosts_new_with_max(), and gvm_hosts_resolve().
unsigned int gvm_hosts_count | ( | const gvm_hosts_t * | hosts | ) |
Gets the count of single hosts objects in a hosts collection.
[in] | hosts | The hosts collection to count hosts of. |
Definition at line 1759 of file hosts.c.
References gvm_hosts::count.
Referenced by gvm_hosts_exclude_with_max().
|
static |
Removes duplicate hosts values from an gvm_hosts_t structure. Also resets the iterator current position.
[in] | hosts | hosts collection from which to remove duplicates. |
Uses a hash table in order to deduplicate the hosts list in O(N) time.
Definition at line 974 of file hosts.c.
References gvm_hosts::count, gvm_hosts::current, gvm_host_free(), gvm_host_value_str(), gvm_hosts_fill_gaps(), gvm_hosts::hosts, gvm_hosts::removed, and gvm_host::vhosts.
Referenced by gvm_hosts_new_with_max(), and gvm_hosts_resolve().
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.
[in] | hosts | The hosts collection from which to exclude. |
[in] | excluded_str | String of hosts to exclude. |
Definition at line 1528 of file hosts.c.
References 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.
[in] | hosts | The hosts collection from which to exclude. |
[in] | excluded_str | String of hosts to exclude. |
[in] | max_hosts | Max number of hosts in hosts_str. 0 means unlimited. |
Uses a hash table in order to exclude hosts in O(N+M) time.
Definition at line 1454 of file hosts.c.
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().
|
static |
Fill the gaps in the array of a hosts collection, which are caused by the removal of host entries.
[in] | hosts | Hosts collection to fill gaps in. |
Definition at line 936 of file hosts.c.
References gvm_hosts::hosts, and gvm_hosts::max_size.
Referenced by gvm_hosts_deduplicate(), gvm_hosts_exclude_with_max(), gvm_hosts_resolve(), gvm_hosts_reverse_lookup_only(), and gvm_hosts_reverse_lookup_unify().
void gvm_hosts_free | ( | gvm_hosts_t * | hosts | ) |
Frees memory occupied by an gvm_hosts_t structure.
[in] | hosts | The hosts collection to free. |
Definition at line 1255 of file hosts.c.
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().
|
static |
Creates a hosts collection from a hosts string.
[in] | hosts_str | String of hosts. |
Definition at line 918 of file hosts.c.
References gvm_hosts::hosts, gvm_hosts::max_size, and gvm_hosts::orig_str.
Referenced by gvm_hosts_new_with_max().
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.
[in] | hosts_str | The hosts string. A copy will be created of this within the returned struct. |
Definition at line 1226 of file hosts.c.
References 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.
[in] | hosts_str | The hosts string. A copy will be created of this within the returned struct. |
[in] | max_hosts | Max number of hosts in hosts_str. 0 means unlimited. |
Definition at line 1031 of file hosts.c.
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().
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.
[in] | hosts | gvm_hosts_t structure to get next host from. |
Definition at line 1240 of file hosts.c.
References gvm_hosts::count, gvm_hosts::current, and gvm_hosts::hosts.
unsigned int gvm_hosts_removed | ( | const gvm_hosts_t * | hosts | ) |
Gets the count of single values in hosts string that were removed (duplicates / excluded.)
[in] | hosts | The hosts collection. |
Definition at line 1773 of file hosts.c.
References gvm_hosts::removed.
void 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.
[in] | hosts | The hosts collection from which to exclude. |
Definition at line 1334 of file hosts.c.
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.
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.
[in] | hosts | The hosts collection to reverse. |
Definition at line 1310 of file hosts.c.
References gvm_hosts::count, gvm_hosts::current, and gvm_hosts::hosts.
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.
[in] | hosts | The hosts collection to filter. |
Definition at line 1670 of file hosts.c.
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.
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.
[in] | hosts | The hosts collection to filter. |
Uses a hash table in order to unify the hosts list in O(N) time.
Definition at line 1709 of file hosts.c.
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.
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.
[in] | hosts | The hosts collection to shuffle. |
Definition at line 1278 of file hosts.c.
References gvm_hosts::count, gvm_hosts::current, and gvm_hosts::hosts.
|
static |
Frees the memory occupied by an gvm_vhost_t object.
[in] | vhost | Vhost to free. |
Definition at line 846 of file hosts.c.
Referenced by gvm_host_free(), and gvm_vhosts_exclude().
gvm_vhost_t* gvm_vhost_new | ( | char * | value, |
char * | source | ||
) |
Creates a new gvm_vhost_t object.
[in] | value | Vhost value. |
[in] | source | Source of hostname. |
Definition at line 829 of file hosts.c.
References gvm_vhost::source, and gvm_vhost::value.
Referenced by gvm_host_add_reverse_lookup(), and gvm_hosts_resolve().
int gvm_vhosts_exclude | ( | gvm_host_t * | host, |
const char * | excluded_str | ||
) |
Exclude a list of vhosts from a host's vhosts list.
[in] | host | The host whose vhosts are to be excluded from. |
[in] | excluded_str | String of hosts to exclude. |
Definition at line 1399 of file hosts.c.
References gvm_vhost_free(), and gvm_host::vhosts.
|
static |
Verifies that hostname value resolves to a host's IP.
[in] | host | The host whose IP is to be checked against. |
[in] | value | Hostname value to verify. |
Definition at line 1596 of file hosts.c.
References addr6_to_str(), gvm_host_value_str(), and gvm_resolve_list().
Referenced by gvm_host_add_reverse_lookup().
|
static |
Checks if a buffer points to an IPv6 CIDR-expressed block. "2620:0:2d0:200::7/120" is valid, "2620:0:2d0:200::7/129" is not.
[in] | str | Buffer to check in. |
Definition at line 428 of file hosts.c.
References is_ipv6_address().
Referenced by gvm_get_host_type().
|
static |
Checks if a buffer points to an IPv4 CIDR-expressed block. "192.168.12.3/24" is valid, "192.168.1.3/31" is not.
[in] | str | Buffer to check in. |
Definition at line 104 of file hosts.c.
References is_ipv4_address().
Referenced by gvm_get_host_type().
|
static |
Checks if a buffer points to a valid hostname. Valid characters include: Alphanumerics, dot (.), dash (-) and underscore (_) up to 255 characters.
[in] | str | Buffer to check in. |
Definition at line 405 of file hosts.c.
Referenced by gvm_get_host_type().
|
static |
Checks if a buffer points to a valid IPv4 address. "192.168.11.1" is valid, "192.168.1.300" and "192.168.1.1e" are not.
[in] | str | Buffer to check in. |
Definition at line 72 of file hosts.c.
Referenced by gvm_get_host_type(), is_cidr_block(), is_long_range_network(), and is_short_range_network().
|
static |
Checks if a buffer points to a valid IPv6 address. "0:0:0:0:0:0:0:1", "::1" and "::FFFF:192.168.13.55" are valid "::1g" is not.
[in] | str | Buffer to check in. |
Definition at line 88 of file hosts.c.
Referenced by gvm_get_host_type(), is_cidr6_block(), is_long_range6_network(), and is_short_range6_network().
|
static |
Checks if a buffer points to a valid long IPv6 range-expressed network. "::fee5-::1:530" is valid.
[in] | str | Buffer to check in. |
Definition at line 599 of file hosts.c.
References is_ipv6_address().
Referenced by gvm_get_host_type().
|
static |
Checks if a buffer points to a valid long range-expressed network. "192.168.12.1-192.168.13.50" is valid.
[in] | str | Buffer to check in. |
Definition at line 239 of file hosts.c.
References is_ipv4_address().
Referenced by gvm_get_host_type().
|
static |
Checks if a buffer points to a valid short IPv6 range-expressed network. "::200:ff:1-fee5" is valid.
str | String to check in. |
Definition at line 674 of file hosts.c.
References is_ipv6_address().
Referenced by gvm_get_host_type().
|
static |
Checks if a buffer points to a valid short range-expressed network. "192.168.11.1-50" is valid, "192.168.1.1-50e" and "192.168.1.1-300" are not.
str | String to check in. |
Definition at line 314 of file hosts.c.
References is_ipv4_address().
Referenced by gvm_get_host_type().
|
static |
Gets the first and last IPv6 addresses from a long range-expressed network. eg. "::1:200:7-::1:205:500" would give ::1:200:7 as first and ::1:205:500 as last.
[in] | str | String containing long IPv6 range-expressed network. |
[out] | first | First IPv6 address in range. |
[out] | last | Last IPv6 address in range. |
Definition at line 634 of file hosts.c.
Referenced by gvm_hosts_new_with_max().
|
static |
Gets the first and last IPv4 addresses from a long range-expressed network. eg. "192.168.1.1-192.168.2.40" would give 192.168.1.1 as first and 192.168.2.40 as last.
[in] | str | String containing long range-expressed network. |
[out] | first | First IP address in block. |
[out] | last | Last IP address in block. |
Definition at line 274 of file hosts.c.
Referenced by gvm_hosts_new_with_max().
|
static |
Gets the first and last IPv6 addresses from a short range-expressed network. eg. "\::ffee:1:1001-1005" would give ::ffee:1:1001 as first and ::ffee:1:1005 as last.
[in] | str | String containing short IPv6 range-expressed network. |
[out] | first | First IPv6 address in range. |
[out] | last | Last IPv6 address in range. |
Definition at line 722 of file hosts.c.
Referenced by gvm_hosts_new_with_max().
|
static |
Gets the first and last IPv4 addresses from a short range-expressed network. "192.168.1.1-40" would give 192.168.1.1 as first and 192.168.1.40 as last.
[in] | str | String containing short range-expressed network. |
[out] | first | First IP address in block. |
[out] | last | Last IP address in block. |
Definition at line 359 of file hosts.c.
Referenced by gvm_hosts_new_with_max().
gchar* host_type_str[HOST_TYPE_MAX] |
Definition at line 53 of file hosts.c.
Referenced by gvm_host_type_str().