OpenVAS Libraries  9.0.1
openvas_hosts.h
Go to the documentation of this file.
1 /* openvas-libraries/base
2  * $Id$
3  * Description: API (structs and protos) for Hosts objects
4  *
5  * Authors:
6  * Hani Benhabiles <hani.benhabiles@greenbone.net>
7  * Jan-Oliver Wagner <jan-oliver.wagner@greenbone.net>
8  *
9  * Copyright:
10  * Copyright (C) 2013 Greenbone Networks GmbH
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26 
35 #ifndef _OPENVAS_HOSTS_H
36 #define _OPENVAS_HOSTS_H
37 
38 #include "openvas_networking.h"
39 
40 #include <glib.h>
41 #include <ctype.h>
42 #include <string.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <arpa/inet.h>
47 #include <netdb.h>
48 
49 /* Static values */
50 
51 enum host_type {
52  HOST_TYPE_NAME = 0, /* Hostname eg. foo */
53  HOST_TYPE_IPV4, /* eg. 192.168.1.1 */
54  HOST_TYPE_CIDR_BLOCK, /* eg. 192.168.15.0/24 */
55  HOST_TYPE_RANGE_SHORT, /* eg. 192.168.15.10-20 */
56  HOST_TYPE_RANGE_LONG, /* eg. 192.168.15.10-192.168.18.3 */
57  HOST_TYPE_IPV6, /* eg. ::1 */
58  HOST_TYPE_CIDR6_BLOCK, /* eg. ::ffee/120 */
59  HOST_TYPE_RANGE6_LONG, /* eg. ::1:200:7-::1:205:500 */
60  HOST_TYPE_RANGE6_SHORT, /* eg. ::1-fe10 */
61  HOST_TYPE_MAX /* Boundary checking. */
62 };
63 
64 /* Typedefs */
67 
68 /* Data structures. */
69 
77 {
78  union {
79  gchar *name; /* Hostname. */
80  struct in_addr addr; /* IPv4 address */
81  struct in6_addr addr6; /* IPv6 address */
82  };
83  enum host_type type; /* HOST_TYPE_NAME, HOST_TYPE_IPV4 or HOST_TYPE_IPV6. */
84 };
85 
93 {
94  gchar *orig_str; /* Original hosts definition string. */
95  GList *hosts; /* Hosts objects list. */
96  GList *current; /* Current host object in iteration. */
97  unsigned int count; /* Number of single host objects in hosts list. */
98  unsigned int removed; /* Number of duplicate/excluded values. */
99 };
100 
101 /* Function prototypes. */
102 
103  /* openvas_hosts_t related */
105 openvas_hosts_new (const gchar *);
106 
108 openvas_hosts_new_with_max (const gchar *, unsigned int);
109 
112 
113 void
115 
116 void
118 
119 void
121 
122 void
124 
125 int
126 openvas_hosts_exclude (openvas_hosts_t *, const gchar *, int);
127 
128 char *
130 
131 int
133 
134 int
136 
137 unsigned int
139 
140 unsigned int
142 
143  /* openvas_host_t related */
144 
145 int
146 openvas_host_in_hosts (const openvas_host_t *, const struct in6_addr *,
147  const openvas_hosts_t *);
148 
149 gchar *
151 
152 enum host_type
154 
155 gchar *
157 
158 int
159 openvas_host_resolve (const openvas_host_t *, void *, int);
160 
161 int
162 openvas_host_get_addr6 (const openvas_host_t *, struct in6_addr *);
163 
164 /* Miscellaneous functions */
165 
166 int
167 openvas_get_host_type (const gchar *);
168 
169 #endif /* not _OPENVAS_HOSTS_H */
The structure for a single host object.
Definition: openvas_hosts.h:76
openvas_host_t * openvas_hosts_next(openvas_hosts_t *)
Gets the next openvas_host_t from a openvas_hosts_t structure. The state of iteration is kept interna...
Definition: openvas_hosts.c:1125
Definition: openvas_hosts.h:60
int openvas_host_resolve(const openvas_host_t *, void *, int)
Resolves a host object&#39;s name to an IPv4 or IPv6 address. Host object should be of type HOST_TYPE_NAM...
Definition: openvas_hosts.c:1697
Definition: openvas_hosts.h:54
unsigned int openvas_hosts_removed(const openvas_hosts_t *)
Gets the count of single values in hosts string that were removed (duplicates / excluded.)
Definition: openvas_hosts.c:1539
Definition: openvas_hosts.h:52
Definition: openvas_hosts.h:53
gchar * openvas_host_type_str(const openvas_host_t *)
Gets a host&#39;s type in printable format.
Definition: openvas_hosts.c:1624
int openvas_hosts_exclude(openvas_hosts_t *, const gchar *, int)
void openvas_hosts_reverse(openvas_hosts_t *)
Reverses the order of the hosts objects in the collection. Not to be used while iterating over the si...
Definition: openvas_hosts.c:1206
unsigned int removed
Definition: openvas_hosts.h:98
Definition: openvas_hosts.h:61
Definition: openvas_hosts.h:55
int openvas_hosts_reverse_lookup_only(openvas_hosts_t *)
Removes hosts that don&#39;t reverse-lookup from the hosts collection. Not to be used while iterating ove...
Definition: openvas_hosts.c:1430
GList * current
Definition: openvas_hosts.h:96
int openvas_host_get_addr6(const openvas_host_t *, struct in6_addr *)
Gives a host object&#39;s value as an IPv6 address. If the host type is hostname, it resolves the IPv4 ad...
Definition: openvas_hosts.c:1718
gchar * orig_str
Definition: openvas_hosts.h:94
char * openvas_host_reverse_lookup(openvas_host_t *)
Checks for a host object reverse dns lookup existence.
Definition: openvas_hosts.c:1378
GList * hosts
Definition: openvas_hosts.h:95
int openvas_get_host_type(const gchar *)
Determines the host type in a buffer.
Definition: openvas_hosts.c:758
struct in_addr addr
Definition: openvas_hosts.h:80
struct in6_addr addr6
Definition: openvas_hosts.h:81
void openvas_hosts_shuffle(openvas_hosts_t *)
Randomizes the order of the hosts objects in the collection. Not to be used while iterating over the ...
Definition: openvas_hosts.c:1166
host_type
Definition: openvas_hosts.h:51
Definition: openvas_hosts.h:58
enum host_type openvas_host_type(const openvas_host_t *)
Gets a host object&#39;s type.
Definition: openvas_hosts.c:1609
The structure for Hosts collection.
Definition: openvas_hosts.h:92
enum host_type type
Definition: openvas_hosts.h:83
gchar * openvas_host_value_str(const openvas_host_t *)
Gets a host&#39;s value in printable format.
Definition: openvas_hosts.c:1640
gchar * name
Definition: openvas_hosts.h:79
Definition: openvas_hosts.h:56
Definition: openvas_hosts.h:59
void openvas_hosts_resolve(openvas_hosts_t *)
Resolves host objects of type name in a hosts collection, replacing hostnames with IPv4 values...
Definition: openvas_hosts.c:1244
unsigned int count
Definition: openvas_hosts.h:97
void openvas_hosts_free(openvas_hosts_t *)
Frees memory occupied by an openvas_hosts_t structure.
Definition: openvas_hosts.c:1145
int openvas_hosts_reverse_lookup_unify(openvas_hosts_t *)
Removes hosts duplicates that reverse-lookup to the same value. Not to be used while iterating over t...
Definition: openvas_hosts.c:1472
openvas_hosts_t * openvas_hosts_new_with_max(const gchar *, unsigned int)
Creates a new openvas_hosts_t structure and the associated hosts objects from the provided hosts_str...
Definition: openvas_hosts.c:912
openvas_hosts_t * openvas_hosts_new(const gchar *)
Creates a new openvas_hosts_t structure and the associated hosts objects from the provided hosts_str...
Definition: openvas_hosts.c:1111
unsigned int openvas_hosts_count(const openvas_hosts_t *)
Gets the count of single hosts objects in a hosts collection.
Definition: openvas_hosts.c:1525
int openvas_host_in_hosts(const openvas_host_t *, const struct in6_addr *, const openvas_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: openvas_hosts.c:1557
Definition: openvas_hosts.h:57