Greenbone Vulnerability Management Libraries  20.8.0
hosts.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2019 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
28 #ifndef _GVM_HOSTS_H
29 #define _GVM_HOSTS_H
30 
31 #include <glib.h> /* for gchar, GList */
32 #include <netinet/in.h> /* for in6_addr, in_addr */
33 
34 /* Static values */
35 
37 {
38  HOST_TYPE_NAME = 0, /* Hostname eg. foo */
39  HOST_TYPE_IPV4, /* eg. 192.168.1.1 */
40  HOST_TYPE_CIDR_BLOCK, /* eg. 192.168.15.0/24 */
41  HOST_TYPE_RANGE_SHORT, /* eg. 192.168.15.10-20 */
42  HOST_TYPE_RANGE_LONG, /* eg. 192.168.15.10-192.168.18.3 */
43  HOST_TYPE_IPV6, /* eg. ::1 */
44  HOST_TYPE_CIDR6_BLOCK, /* eg. ::ffee/120 */
45  HOST_TYPE_RANGE6_LONG, /* eg. ::1:200:7-::1:205:500 */
46  HOST_TYPE_RANGE6_SHORT, /* eg. ::1-fe10 */
47  HOST_TYPE_MAX /* Boundary checking. */
48 };
49 
50 /* Typedefs */
51 typedef struct gvm_host gvm_host_t;
52 typedef struct gvm_vhost gvm_vhost_t;
53 typedef struct gvm_hosts gvm_hosts_t;
54 
55 /* Data structures. */
56 
63 struct gvm_host
64 {
65  union
66  {
67  gchar *name;
68  struct in_addr addr;
69  struct in6_addr addr6;
70  };
71  enum host_type type;
72  GSList *vhosts;
73 };
74 
78 struct gvm_vhost
79 {
80  char *value;
81  char *source;
82 };
83 
90 struct gvm_hosts
91 {
92  gchar *orig_str;
94  size_t max_size;
95  size_t current;
96  size_t count;
97  size_t removed;
98 };
99 
100 /* Function prototypes. */
101 
102 /* gvm_hosts_t related */
103 
104 gvm_hosts_t *
105 gvm_hosts_new (const gchar *);
106 
107 gvm_hosts_t *
108 gvm_hosts_new_with_max (const gchar *, unsigned int);
109 
110 gvm_host_t *
112 
113 void
115 
116 void
118 
119 void
121 
122 void
124 
125 GSList *
127 
128 int
129 gvm_hosts_exclude (gvm_hosts_t *, const char *);
130 
131 int
132 gvm_vhosts_exclude (gvm_host_t *, const char *);
133 
134 int
135 gvm_hosts_exclude_with_max (gvm_hosts_t *, const char *, unsigned int);
136 
137 char *
139 
140 int
142 
143 int
145 
146 unsigned int
147 gvm_hosts_count (const gvm_hosts_t *);
148 
149 unsigned int
151 
152 /* gvm_host_t related */
153 
154 gvm_host_t *
155 gvm_host_from_str (const gchar *hosts_str);
156 
157 int
158 gvm_host_in_hosts (const gvm_host_t *, const struct in6_addr *,
159  const gvm_hosts_t *);
160 
161 gchar *
162 gvm_host_type_str (const gvm_host_t *);
163 
164 enum host_type
165 gvm_host_type (const gvm_host_t *);
166 
167 gchar *
169 
170 int
171 gvm_host_resolve (const gvm_host_t *, void *, int);
172 
173 int
174 gvm_host_get_addr6 (const gvm_host_t *, struct in6_addr *);
175 
176 void
178 
179 /* Miscellaneous functions */
180 
181 gvm_vhost_t *
182 gvm_vhost_new (char *, char *);
183 
184 int
185 gvm_get_host_type (const gchar *);
186 
187 #endif /* not _GVM_HOSTS_H */
gvm_host::name
gchar * name
Definition: hosts.h:67
gvm_hosts::count
size_t count
Definition: hosts.h:96
gvm_host_resolve
int gvm_host_resolve(const gvm_host_t *, void *, int)
Resolves a host object's name to an IPv4 or IPv6 address. Host object should be of type HOST_TYPE_NAM...
Definition: hosts.c:2042
gvm_hosts_new
gvm_hosts_t * gvm_hosts_new(const gchar *)
Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str.
Definition: hosts.c:1285
gvm_hosts::removed
size_t removed
Definition: hosts.h:97
gvm_host_type
enum host_type gvm_host_type(const gvm_host_t *)
Gets a host object's type.
Definition: hosts.c:1954
gvm_hosts_reverse_lookup_only
int gvm_hosts_reverse_lookup_only(gvm_hosts_t *)
Removes hosts that don't reverse-lookup from the hosts collection. Not to be used while iterating ove...
Definition: hosts.c:1783
gvm_host_value_str
gchar * gvm_host_value_str(const gvm_host_t *)
Gets a host's value in printable format.
Definition: hosts.c:1985
HOST_TYPE_IPV6
@ HOST_TYPE_IPV6
Definition: hosts.h:43
gvm_host_from_str
gvm_host_t * gvm_host_from_str(const gchar *hosts_str)
Creates a new gvm_host_t from a host string.
Definition: hosts.c:1608
gvm_hosts::max_size
size_t max_size
Definition: hosts.h:94
gvm_vhost_new
gvm_vhost_t * gvm_vhost_new(char *, char *)
Creates a new gvm_vhost_t object.
Definition: hosts.c:884
HOST_TYPE_RANGE_SHORT
@ HOST_TYPE_RANGE_SHORT
Definition: hosts.h:41
gvm_hosts_next
gvm_host_t * gvm_hosts_next(gvm_hosts_t *)
Gets the next gvm_host_t from a gvm_hosts_t structure. The state of iteration is kept internally with...
Definition: hosts.c:1299
gvm_host::type
enum host_type type
Definition: hosts.h:71
gvm_hosts_exclude
int gvm_hosts_exclude(gvm_hosts_t *, const char *)
Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating ...
Definition: hosts.c:1592
gvm_vhost
The structure for a single vhost object.
Definition: hosts.h:79
HOST_TYPE_IPV4
@ HOST_TYPE_IPV4
Definition: hosts.h:39
gvm_hosts_shuffle
void gvm_hosts_shuffle(gvm_hosts_t *)
Randomizes the order of the hosts objects in the collection. Not to be used while iterating over the ...
Definition: hosts.c:1337
gvm_hosts::hosts
gvm_host_t ** hosts
Definition: hosts.h:93
gvm_host_type_str
gchar * gvm_host_type_str(const gvm_host_t *)
Gets a host's type in printable format.
Definition: hosts.c:1969
gvm_host
The structure for a single host object.
Definition: hosts.h:64
HOST_TYPE_CIDR6_BLOCK
@ HOST_TYPE_CIDR6_BLOCK
Definition: hosts.h:44
gvm_hosts_count
unsigned int gvm_hosts_count(const gvm_hosts_t *)
Gets the count of single hosts objects in a hosts collection.
Definition: hosts.c:1872
gvm_hosts::current
size_t current
Definition: hosts.h:95
gvm_vhost::value
char * value
Definition: hosts.h:80
HOST_TYPE_RANGE_LONG
@ HOST_TYPE_RANGE_LONG
Definition: hosts.h:42
gvm_host_get_addr6
int gvm_host_get_addr6(const gvm_host_t *, struct in6_addr *)
Gives a host object's value as an IPv6 address. If the host type is hostname, it resolves the IPv4 ad...
Definition: hosts.c:2063
gvm_host::addr
struct in_addr addr
Definition: hosts.h:68
gvm_host_add_reverse_lookup
void gvm_host_add_reverse_lookup(gvm_host_t *)
Add a host's reverse-lookup name to the vhosts list.
Definition: hosts.c:1741
HOST_TYPE_RANGE6_LONG
@ HOST_TYPE_RANGE6_LONG
Definition: hosts.h:45
gvm_hosts_free
void gvm_hosts_free(gvm_hosts_t *)
Frees memory occupied by an gvm_hosts_t structure.
Definition: hosts.c:1314
gvm_get_host_type
int gvm_get_host_type(const gchar *)
Determines the host type in a buffer.
Definition: hosts.c:823
gvm_vhost::source
char * source
Definition: hosts.h:81
gvm_host_reverse_lookup
char * gvm_host_reverse_lookup(gvm_host_t *)
Checks for a host object reverse dns lookup existence.
Definition: hosts.c:1657
HOST_TYPE_MAX
@ HOST_TYPE_MAX
Definition: hosts.h:47
gvm_hosts::orig_str
gchar * orig_str
Definition: hosts.h:92
host_type
host_type
Definition: hosts.h:37
gvm_host_in_hosts
int gvm_host_in_hosts(const gvm_host_t *, const struct in6_addr *, const gvm_hosts_t *)
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:1904
gvm_host::addr6
struct in6_addr addr6
Definition: hosts.h:69
HOST_TYPE_CIDR_BLOCK
@ HOST_TYPE_CIDR_BLOCK
Definition: hosts.h:40
gvm_hosts_resolve
GSList * gvm_hosts_resolve(gvm_hosts_t *)
Resolves host objects of type name in a hosts collection, replacing hostnames with IPv4 values....
Definition: hosts.c:1395
HOST_TYPE_RANGE6_SHORT
@ HOST_TYPE_RANGE6_SHORT
Definition: hosts.h:46
gvm_hosts_reverse
void gvm_hosts_reverse(gvm_hosts_t *)
Reverses the order of the hosts objects in the collection. Not to be used while iterating over the si...
Definition: hosts.c:1369
gvm_hosts_reverse_lookup_unify
int gvm_hosts_reverse_lookup_unify(gvm_hosts_t *)
Removes hosts duplicates that reverse-lookup to the same value. Not to be used while iterating over t...
Definition: hosts.c:1822
gvm_hosts_exclude_with_max
int gvm_hosts_exclude_with_max(gvm_hosts_t *, const char *, unsigned int)
Excludes a set of hosts provided as a string from a hosts collection. Not to be used while iterating ...
Definition: hosts.c:1518
gvm_hosts_add
void gvm_hosts_add(gvm_hosts_t *, gvm_host_t *)
Inserts a host object at the end of a hosts collection.
Definition: hosts.c:953
gvm_hosts_removed
unsigned int gvm_hosts_removed(const gvm_hosts_t *)
Gets the count of single values in hosts string that were removed (duplicates / excluded....
Definition: hosts.c:1886
HOST_TYPE_NAME
@ HOST_TYPE_NAME
Definition: hosts.h:38
gvm_hosts_new_with_max
gvm_hosts_t * gvm_hosts_new_with_max(const gchar *, unsigned int)
Creates a new gvm_hosts_t structure and the associated hosts objects from the provided hosts_str.
Definition: hosts.c:1088
gvm_host::vhosts
GSList * vhosts
Definition: hosts.h:72
gvm_hosts
The structure for Hosts collection.
Definition: hosts.h:91
gvm_vhosts_exclude
int gvm_vhosts_exclude(gvm_host_t *, const char *)
Exclude a list of vhosts from a host's vhosts list.
Definition: hosts.c:1463