From ef6326a174e6880be5e2eaeac26a2c5de0768807 Mon Sep 17 00:00:00 2001 From: Andrej Rode Date: Tue, 21 Mar 2017 19:46:50 -0700 Subject: mpm: python refactoring --- mpm/lib/net_helper.hpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 mpm/lib/net_helper.hpp (limited to 'mpm/lib/net_helper.hpp') diff --git a/mpm/lib/net_helper.hpp b/mpm/lib/net_helper.hpp new file mode 100644 index 000000000..b07e43ccc --- /dev/null +++ b/mpm/lib/net_helper.hpp @@ -0,0 +1,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 . +// + +#include +#include +#include + +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 ip_addr; +}; + +/*! + * net_ifaces contains a pair + * describing mac address and associated ip addresses for + * each interface + */ +using net_ifaces = std::map; + +/*! + * 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 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 + -- cgit v1.2.3