blob: b07e43cccead3cd863360894a4059311d9f8a204 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//
// Copyright 2017 Ettus Research (National Instruments)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <map>
#include <vector>
#include <string>
namespace mpm {
namespace network {
/*!
* A struct describing a single network interface
*/
using net_iface = struct net_iface {
/*! MAC address of the interface in the form AABBCCDDEEFF */
std::string mac_addr;
/*! vector of associated IP addresses, contains both IPv4 and IPv6 */
std::vector<std::string> ip_addr;
};
/*!
* net_ifaces contains a <interfaces name, net_iface> pair
* describing mac address and associated ip addresses for
* each interface
*/
using net_ifaces = std::map<std::string, net_iface>;
/*!
* Convenience function to get all ip addresses of one MAC address
* \param MAC address in the form AABBCCDDEEFF
* \return vector of strings containing all IP addresses with this MAC address
*/
std::vector<std::string> get_if_addrs(const std::string& mac_addr);
/*!
* Get information about all interfaces on this system
* \return a map with interface names as keys and the interfaces information as value
*/
net_ifaces get_net_map();
/*!
* Pretty print net_ifaces in the style of `ip addr`
* \param interface map net_ifaces to print
*/
void print_net_ifaces(net_ifaces my_ifaces);
}
}
#ifdef LIBMPM_PYTHON
void export_net_iface(){
LIBMPM_BOOST_PREAMBLE("network")
bp::def("get_if_addrs", &mpm::network::get_if_addrs);
}
#endif
|