libtins 4.5
Loading...
Searching...
No Matches
routing_utils.h
1/*
2 * Copyright (c) 2017, Matias Fontanini
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#ifndef TINS_ROUTING_UTILS_H
31#define TINS_ROUTING_UTILS_H
32
33#include <vector>
34#include <set>
35#include <tins/macros.h>
36#include <tins/ip_address.h>
37#include <tins/ipv6_address.h>
38
39// Fix for Windows interface define on combaseapi.h
40#undef interface
41
42namespace Tins {
43namespace Utils {
44
74
104
110template<typename ForwardIterator>
111void route_entries(ForwardIterator output);
112
118template<typename ForwardIterator>
119void route6_entries(ForwardIterator output);
120
126TINS_API std::vector<RouteEntry> route_entries();
127
128
134TINS_API std::vector<Route6Entry> route6_entries();
135
143TINS_API std::set<std::string> network_interfaces();
144
156TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address& gw_addr);
157
169TINS_API bool gateway_from_ip(IPv6Address ip, IPv6Address& gw_addr);
170
171} // Utils
172} // Tins
173
174template<typename ForwardIterator>
175void Tins::Utils::route_entries(ForwardIterator output) {
176 std::vector<RouteEntry> entries = route_entries();
177 for (size_t i = 0; i < entries.size(); ++i) {
178 *output = entries[i];
179 ++output;
180 }
181}
182
183template<typename ForwardIterator>
184void Tins::Utils::route6_entries(ForwardIterator output) {
185 std::vector<Route6Entry> entries = route6_entries();
186 for (size_t i = 0; i < entries.size(); ++i) {
187 *output = entries[i];
188 ++output;
189 }
190}
191
192#endif // TINS_ROUTING_UTILS_H
Abstraction of an IPv4 address.
Definition ip_address.h:45
Definition ipv6_address.h:45
TINS_API std::vector< Route6Entry > route6_entries()
Retrieves entries in the routing table.
Definition routing_utils.cpp:360
TINS_API bool gateway_from_ip(IPv4Address ip, IPv4Address &gw_addr)
Finds the gateway's IP address for the given IP address.
Definition routing_utils.cpp:434
TINS_API std::set< std::string > network_interfaces()
List all network interfaces.
Definition routing_utils.cpp:415
void route6_entries(ForwardIterator output)
Retrieves entries in the routing table.
Definition routing_utils.h:184
TINS_API std::vector< RouteEntry > route_entries()
Retrieves entries in the routing table.
Definition routing_utils.cpp:333
void route_entries(ForwardIterator output)
Retrieves entries in the routing table.
Definition routing_utils.h:175
The Tins namespace.
Definition address_range.h:38
Definition routing_utils.h:78
IPv6Address mask
Definition routing_utils.h:92
IPv6Address gateway
Definition routing_utils.h:97
IPv6Address destination
Definition routing_utils.h:87
std::string interface
Definition routing_utils.h:82
int metric
Definition routing_utils.h:102
Definition routing_utils.h:48
IPv4Address gateway
Definition routing_utils.h:62
IPv4Address mask
Definition routing_utils.h:67
int metric
Definition routing_utils.h:72
IPv4Address destination
Definition routing_utils.h:57
std::string interface
Definition routing_utils.h:52