blob: 32caaed1f3931f6513e7d74edab8339a56a9149a [file] [log] [blame]
Davide Pesavento248d6bd2014-03-09 10:24:08 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento43ff2a92017-05-18 19:50:57 -04003 * Copyright (c) 2014-2017, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi3ffe66d2014-11-06 15:37:59 -070024 */
Davide Pesavento248d6bd2014-03-09 10:24:08 +010025
26#ifndef NFD_CORE_NETWORK_INTERFACE_HPP
27#define NFD_CORE_NETWORK_INTERFACE_HPP
28
29#include "common.hpp"
Davide Pesavento248d6bd2014-03-09 10:24:08 +010030
Junxiao Shia1937bf2014-11-06 11:43:40 -070031#include <ndn-cxx/util/ethernet.hpp>
32
Davide Pesaventob499a602014-11-18 22:36:56 +010033#include <net/if.h>
34
Davide Pesavento248d6bd2014-03-09 10:24:08 +010035namespace nfd {
36
Davide Pesavento43ff2a92017-05-18 19:50:57 -040037namespace ethernet {
38using namespace ndn::util::ethernet;
39} // namespace ethernet
Junxiao Shia1937bf2014-11-06 11:43:40 -070040
41/** \brief contains information about a network interface
42 */
Davide Pesavento248d6bd2014-03-09 10:24:08 +010043class NetworkInterfaceInfo
44{
45public:
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060046
Davide Pesavento248d6bd2014-03-09 10:24:08 +010047 int index;
48 std::string name;
49 ethernet::Address etherAddress;
50 std::vector<boost::asio::ip::address_v4> ipv4Addresses;
51 std::vector<boost::asio::ip::address_v6> ipv6Addresses;
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060052 boost::asio::ip::address_v4 broadcastAddress;
Davide Pesavento248d6bd2014-03-09 10:24:08 +010053 unsigned int flags;
54
55 bool
56 isLoopback() const;
57
58 bool
59 isMulticastCapable() const;
60
61 bool
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060062 isBroadcastCapable() const;
63
64 bool
Davide Pesavento248d6bd2014-03-09 10:24:08 +010065 isUp() const;
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060066
Davide Pesavento248d6bd2014-03-09 10:24:08 +010067};
68
69inline bool
70NetworkInterfaceInfo::isLoopback() const
71{
72 return (flags & IFF_LOOPBACK) != 0;
73}
74
75inline bool
76NetworkInterfaceInfo::isMulticastCapable() const
77{
78 return (flags & IFF_MULTICAST) != 0;
79}
80
81inline bool
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060082NetworkInterfaceInfo::isBroadcastCapable() const
83{
84 return (flags & IFF_BROADCAST) != 0;
85}
86
87inline bool
Davide Pesavento248d6bd2014-03-09 10:24:08 +010088NetworkInterfaceInfo::isUp() const
89{
90 return (flags & IFF_UP) != 0;
91}
92
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -080093/** \brief List configured network interfaces on the system and their info
Alexander Afanasyev7e148162014-12-15 12:05:37 -080094 * \warning invalid IP addresses (e.g., 0.0.0.0) may be returned in some environments
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -080095 */
Davide Pesaventob499a602014-11-18 22:36:56 +010096std::vector<NetworkInterfaceInfo>
Davide Pesavento248d6bd2014-03-09 10:24:08 +010097listNetworkInterfaces();
98
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -080099#ifdef WITH_TESTS
100/** \brief Set a list of network interfaces to be returned by subsequent listNetworkInterfaces call
101 * \note To reset to normal behavior, use `setDebugNetworkInterfaces(nullptr);`
102 */
103void
104setDebugNetworkInterfaces(shared_ptr<std::vector<NetworkInterfaceInfo>> interfaces);
105#endif
106
Davide Pesavento248d6bd2014-03-09 10:24:08 +0100107} // namespace nfd
108
109#endif // NFD_CORE_NETWORK_INTERFACE_HPP