OpenVAS Libraries  8.0.3
Functions | Variables
openvas_hosts.c File Reference
#include "openvas_hosts.h"

Functions

int openvas_get_host_type (const gchar *str_stripped)
 Determines the host type in a buffer. More...
 
openvas_hosts_topenvas_hosts_new_with_max (const gchar *hosts_str, unsigned int max_hosts)
 Creates a new openvas_hosts_t structure and the associated hosts objects from the provided hosts_str. More...
 
openvas_hosts_topenvas_hosts_new (const gchar *hosts_str)
 Creates a new openvas_hosts_t structure and the associated hosts objects from the provided hosts_str. More...
 
openvas_host_topenvas_hosts_next (openvas_hosts_t *hosts)
 Gets the next openvas_host_t from a openvas_hosts_t structure. The state of iteration is kept internally within the openvas_hosts structure. More...
 
void openvas_hosts_free (openvas_hosts_t *hosts)
 Frees memory occupied by an openvas_hosts_t structure. More...
 
void openvas_hosts_shuffle (openvas_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 openvas_hosts_reverse (openvas_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 openvas_hosts_resolve (openvas_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 openvas_hosts_exclude (openvas_hosts_t *hosts, const char *excluded_str, int resolve)
 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 * openvas_host_reverse_lookup (openvas_host_t *host)
 Checks for a host object reverse dns lookup existence. More...
 
int openvas_hosts_reverse_lookup_only (openvas_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 openvas_hosts_reverse_lookup_unify (openvas_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 openvas_hosts_count (const openvas_hosts_t *hosts)
 Gets the count of single hosts objects in a hosts collection. More...
 
unsigned int openvas_hosts_removed (const openvas_hosts_t *hosts)
 Gets the count of single values in hosts string that were removed (duplicates / excluded.) More...
 
int openvas_host_in_hosts (const openvas_host_t *host, const struct in6_addr *addr, const openvas_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...
 
int openvas_host_type (const openvas_host_t *host)
 Gets a host object's type. More...
 
gchar * openvas_host_type_str (const openvas_host_t *host)
 Gets a host's type in printable format. More...
 
gchar * openvas_host_value_str (const openvas_host_t *host)
 Gets a host's value in printable format. More...
 
int openvas_host_resolve (const openvas_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 openvas_host_get_addr6 (const openvas_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]
 

Function Documentation

int openvas_get_host_type ( const gchar *  str_stripped)

Determines the host type in a buffer.

Parameters
[in]strBuffer that contains host definition, could a be hostname, single IPv4 or IPv6, CIDR-expressed block etc,.
Returns
Host_TYPE_*, -1 if error.
int openvas_host_get_addr6 ( const openvas_host_t host,
struct in6_addr *  ip6 
)

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

Parameters
[in]hostThe host object whose value to get as IPv6.
[out]ip6Buffer to store the IPv6 address.
Returns
-1 if error, 0 otherwise.
int openvas_host_in_hosts ( const openvas_host_t host,
const struct in6_addr *  addr,
const openvas_hosts_t hosts 
)

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

Parameters
[in]hostThe host object.
[in]addrOptional pointer to ip address. Could be used so that host isn't resolved multiple times when type is HOST_TYPE_NAME.
[in]hostsHosts collection.
Returns
1 if host has equal in hosts, 0 otherwise.
int openvas_host_resolve ( const openvas_host_t host,
void *  dst,
int  family 
)

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

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

Checks for a host object reverse dns lookup existence.

Parameters
[in]hostThe host to reverse-lookup.
Returns
Result of look-up or name if host of type name already, NULL otherwise. Free with g_free().
int openvas_host_type ( const openvas_host_t host)

Gets a host object's type.

Parameters
[in]hostThe host object.
Returns
Host type.
gchar* openvas_host_type_str ( const openvas_host_t host)

Gets a host's type in printable format.

Parameters
[in]hostThe host object.
Returns
String representing host type. Statically allocated, thus, not to be freed.
gchar* openvas_host_value_str ( const openvas_host_t host)

Gets a host's value in printable format.

Parameters
[in]hostThe host object.
Returns
String representing host value. To be freed with g_free().
unsigned int openvas_hosts_count ( const openvas_hosts_t hosts)

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

Parameters
[in]hostsThe hosts collection to count hosts of.
Returns
The number of single hosts.
int openvas_hosts_exclude ( openvas_hosts_t hosts,
const char *  excluded_str,
int  resolve 
)

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

Parameters
[in]hostsThe hosts collection from which to exclude.
[in]excluded_strString of hosts to exclude.
[in]resolveBoolean. Whether to also resolve hostnames when excluding.
Returns
Number of excluded hosts, -1 if error.

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

void openvas_hosts_free ( openvas_hosts_t hosts)

Frees memory occupied by an openvas_hosts_t structure.

Parameters
[in]hostsThe hosts collection to free.
openvas_hosts_t* openvas_hosts_new ( const gchar *  hosts_str)

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

Parameters
[in]hosts_strThe hosts string. A copy will be created of this within the returned struct.
Returns
NULL if error, otherwise, a hosts structure that should be released using openvas_hosts_free.
openvas_hosts_t* openvas_hosts_new_with_max ( const gchar *  hosts_str,
unsigned int  max_hosts 
)

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

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

Gets the next openvas_host_t from a openvas_hosts_t structure. The state of iteration is kept internally within the openvas_hosts structure.

Parameters
[in]hostsopenvas_hosts_t structure to get next host from.
Returns
Pointer to host. NULL if error or end of hosts.
unsigned int openvas_hosts_removed ( const openvas_hosts_t hosts)

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

Parameters
[in]hostsThe hosts collection.
Returns
The number of removed values.
void openvas_hosts_resolve ( openvas_hosts_t hosts)

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

Parameters
[in]hostsThe hosts collection from which to exclude.
void openvas_hosts_reverse ( openvas_hosts_t hosts)

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

Parameters
[in]hostsThe hosts collection to reverse.
int openvas_hosts_reverse_lookup_only ( openvas_hosts_t hosts)

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

Parameters
[in]hostsThe hosts collection to filter.
Returns
Number of hosts removed, -1 if error.
int openvas_hosts_reverse_lookup_unify ( openvas_hosts_t hosts)

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

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

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

void openvas_hosts_shuffle ( openvas_hosts_t hosts)

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

Parameters
[in]hostsThe hosts collection to shuffle.

Variable Documentation

gchar* host_type_str[HOST_TYPE_MAX]
Initial value:
= {
[HOST_TYPE_NAME] = "Hostname",
[HOST_TYPE_IPV4] = "IPv4",
[HOST_TYPE_IPV6] = "IPv6",
[HOST_TYPE_CIDR_BLOCK] = "IPv4 CIDR block",
[HOST_TYPE_RANGE_SHORT] = "IPv4 short range",
[HOST_TYPE_RANGE_LONG] = "IPv4 long range"
}
Definition: openvas_hosts.h:54
Definition: openvas_hosts.h:52
Definition: openvas_hosts.h:53
Definition: openvas_hosts.h:55
Definition: openvas_hosts.h:56
Definition: openvas_hosts.h:57