blob: 8519db149253be1fb56a2665ccc1366af1a966c3 [file] [log] [blame]
Davide Pesavento248d6bd2014-03-09 10:24:08 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi3ffe66d2014-11-06 15:37:59 -07003 * Copyright (c) 2014, 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
Junxiao Shia1937bf2014-11-06 11:43:40 -070037namespace ethernet = ndn::util::ethernet;
38
39/** \brief contains information about a network interface
40 */
Davide Pesavento248d6bd2014-03-09 10:24:08 +010041class NetworkInterfaceInfo
42{
43public:
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060044
Davide Pesavento248d6bd2014-03-09 10:24:08 +010045 int index;
46 std::string name;
47 ethernet::Address etherAddress;
48 std::vector<boost::asio::ip::address_v4> ipv4Addresses;
49 std::vector<boost::asio::ip::address_v6> ipv6Addresses;
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060050 boost::asio::ip::address_v4 broadcastAddress;
Davide Pesavento248d6bd2014-03-09 10:24:08 +010051 unsigned int flags;
52
53 bool
54 isLoopback() const;
55
56 bool
57 isMulticastCapable() const;
58
59 bool
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060060 isBroadcastCapable() const;
61
62 bool
Davide Pesavento248d6bd2014-03-09 10:24:08 +010063 isUp() const;
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060064
Davide Pesavento248d6bd2014-03-09 10:24:08 +010065};
66
67inline bool
68NetworkInterfaceInfo::isLoopback() const
69{
70 return (flags & IFF_LOOPBACK) != 0;
71}
72
73inline bool
74NetworkInterfaceInfo::isMulticastCapable() const
75{
76 return (flags & IFF_MULTICAST) != 0;
77}
78
79inline bool
Steve DiBenedettoca53ac62014-03-27 19:58:40 -060080NetworkInterfaceInfo::isBroadcastCapable() const
81{
82 return (flags & IFF_BROADCAST) != 0;
83}
84
85inline bool
Davide Pesavento248d6bd2014-03-09 10:24:08 +010086NetworkInterfaceInfo::isUp() const
87{
88 return (flags & IFF_UP) != 0;
89}
90
Davide Pesaventob499a602014-11-18 22:36:56 +010091std::vector<NetworkInterfaceInfo>
Davide Pesavento248d6bd2014-03-09 10:24:08 +010092listNetworkInterfaces();
93
94} // namespace nfd
95
96#endif // NFD_CORE_NETWORK_INTERFACE_HPP