blob: b94fabd1383fde7607ca95e90b16919a116e0339 [file] [log] [blame]
Davide Pesavento248d6bd2014-03-09 10:24:08 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shi0d82d042017-07-07 06:15:27 +00002/*
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"
Junxiao Shi83be1da2017-06-30 13:37:37 +000030#include <ndn-cxx/net/ethernet.hpp>
Junxiao Shi0d82d042017-07-07 06:15:27 +000031#include <ndn-cxx/net/network-interface.hpp>
Junxiao Shia1937bf2014-11-06 11:43:40 -070032
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 {
Junxiao Shi83be1da2017-06-30 13:37:37 +000038using namespace ndn::ethernet;
Davide Pesavento43ff2a92017-05-18 19:50:57 -040039} // 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:
Davide Pesavento248d6bd2014-03-09 10:24:08 +010046 bool
47 isLoopback() const;
48
49 bool
50 isMulticastCapable() const;
51
52 bool
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060053 isBroadcastCapable() const;
54
55 bool
Davide Pesavento248d6bd2014-03-09 10:24:08 +010056 isUp() const;
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060057
Junxiao Shi0d82d042017-07-07 06:15:27 +000058 /** \brief Export to ndn::net::NetworkInterface
59 * \warning This is a temporary adaptation during the transition from NetworkInterfaceInfo to
60 * ndn::net::NetworkInterface. The return value carries the information in this instance
61 * and will not track changes in the actual network interface or emit signals.
62 */
63 shared_ptr<ndn::net::NetworkInterface>
64 asNetworkInterface() const;
65
66public:
67 int index;
68 std::string name;
69 ethernet::Address etherAddress;
70 std::vector<boost::asio::ip::address_v4> ipv4Addresses;
71 std::vector<boost::asio::ip::address_v6> ipv6Addresses;
72 boost::asio::ip::address_v4 broadcastAddress;
73 unsigned int flags;
Davide Pesavento248d6bd2014-03-09 10:24:08 +010074};
75
76inline bool
77NetworkInterfaceInfo::isLoopback() const
78{
79 return (flags & IFF_LOOPBACK) != 0;
80}
81
82inline bool
83NetworkInterfaceInfo::isMulticastCapable() const
84{
85 return (flags & IFF_MULTICAST) != 0;
86}
87
88inline bool
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060089NetworkInterfaceInfo::isBroadcastCapable() const
90{
91 return (flags & IFF_BROADCAST) != 0;
92}
93
94inline bool
Davide Pesavento248d6bd2014-03-09 10:24:08 +010095NetworkInterfaceInfo::isUp() const
96{
97 return (flags & IFF_UP) != 0;
98}
99
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -0800100/** \brief List configured network interfaces on the system and their info
Alexander Afanasyev7e148162014-12-15 12:05:37 -0800101 * \warning invalid IP addresses (e.g., 0.0.0.0) may be returned in some environments
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -0800102 */
Davide Pesaventob499a602014-11-18 22:36:56 +0100103std::vector<NetworkInterfaceInfo>
Davide Pesavento248d6bd2014-03-09 10:24:08 +0100104listNetworkInterfaces();
105
Alexander Afanasyev70aaf8a2014-12-13 00:44:22 -0800106#ifdef WITH_TESTS
107/** \brief Set a list of network interfaces to be returned by subsequent listNetworkInterfaces call
108 * \note To reset to normal behavior, use `setDebugNetworkInterfaces(nullptr);`
109 */
110void
111setDebugNetworkInterfaces(shared_ptr<std::vector<NetworkInterfaceInfo>> interfaces);
112#endif
113
Davide Pesavento248d6bd2014-03-09 10:24:08 +0100114} // namespace nfd
115
116#endif // NFD_CORE_NETWORK_INTERFACE_HPP