1 /* Copyright (C) 2013-2021 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 
20 /**
21  * @file
22  * @brief GVM Networking related API.
23  */
24 
25 #ifndef _GVM_NETWORKING_H
26 #define _GVM_NETWORKING_H
27 
28 #include "array.h" /* for array_t */
29 
30 #include <netinet/in.h>
31 #include <netdb.h> /* for struct in6_addr */
32 #include <sys/socket.h> /* for struct sockaddr_storage */
33 
34 /**
35  * @brief Possible port types.
36  *
37  * Used in Manager database. If any symbol changes then a migrator must be
38  * added to update existing data.
39  */
40 typedef enum
41 {
42   PORT_PROTOCOL_TCP = 0,
43   PORT_PROTOCOL_UDP = 1,
44   PORT_PROTOCOL_OTHER = 2
45 } port_protocol_t;
46 
47 /**
48  * @brief A port range.
49  */
50 struct range
51 {
52   gchar *comment;       /**< Comment. */
53   gchar *id;            /**< UUID. */
54   int end;              /**< End port. For single port end == start. */
55   int exclude;          /**< Whether to exclude range. */
56   int start;            /**< Start port. */
57   port_protocol_t type; /**< Port protocol. */
58 };
59 typedef struct range range_t;
60 
61 int
62 gvm_source_iface_init (const char *);
63 
64 int
65 gvm_source_iface_is_set (void);
66 
67 int
68 gvm_source_set_socket (int, int, int);
69 
70 void
71 gvm_source_addr (void *);
72 
73 void
74 gvm_source_addr6 (void *);
75 
76 void
77 gvm_source_addr_as_addr6 (struct in6_addr *);
78 
79 char *
80 gvm_source_addr_str (void);
81 
82 char *
83 gvm_source_addr6_str (void);
84 
85 void
86 ipv4_as_ipv6 (const struct in_addr *, struct in6_addr *);
87 
88 void
89 addr6_to_str (const struct in6_addr *, char *);
90 
91 char *
92 addr6_as_str (const struct in6_addr *);
93 
94 void
95 sockaddr_as_str (const struct sockaddr_storage *, char *);
96 
97 int
98 gvm_resolve (const char *, void *, int);
99 
100 GSList *
101 gvm_resolve_list (const char *);
102 
103 int
104 gvm_resolve_as_addr6 (const char *, struct in6_addr *);
105 
106 int
107 validate_port_range (const char *);
108 
109 array_t *
110 port_range_ranges (const char *);
111 
112 int
113 port_in_port_ranges (int, port_protocol_t, array_t *);
114 
115 int
116 ipv6_is_enabled ();
117 
118 gchar *
119 gvm_routethrough (struct sockaddr_storage *, struct sockaddr_storage *);
120 
121 #endif /* not _GVM_NETWORKING_H */
122