Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 3ffe66d | 2014-11-06 15:37:59 -0700 | [diff] [blame] | 3 | * 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 Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 10 | * |
| 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 Shi | 3ffe66d | 2014-11-06 15:37:59 -0700 | [diff] [blame] | 24 | */ |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 25 | |
| 26 | #ifndef NFD_CORE_NETWORK_INTERFACE_HPP |
| 27 | #define NFD_CORE_NETWORK_INTERFACE_HPP |
| 28 | |
| 29 | #include "common.hpp" |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 30 | |
| 31 | #include <net/if.h> |
| 32 | |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/util/ethernet.hpp> |
| 34 | |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 35 | namespace nfd { |
| 36 | |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 37 | namespace ethernet = ndn::util::ethernet; |
| 38 | |
| 39 | /** \brief contains information about a network interface |
| 40 | */ |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 41 | class NetworkInterfaceInfo |
| 42 | { |
| 43 | public: |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 44 | |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 45 | 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 DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 50 | boost::asio::ip::address_v4 broadcastAddress; |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 51 | unsigned int flags; |
| 52 | |
| 53 | bool |
| 54 | isLoopback() const; |
| 55 | |
| 56 | bool |
| 57 | isMulticastCapable() const; |
| 58 | |
| 59 | bool |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 60 | isBroadcastCapable() const; |
| 61 | |
| 62 | bool |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 63 | isUp() const; |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 64 | |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | inline bool |
| 68 | NetworkInterfaceInfo::isLoopback() const |
| 69 | { |
| 70 | return (flags & IFF_LOOPBACK) != 0; |
| 71 | } |
| 72 | |
| 73 | inline bool |
| 74 | NetworkInterfaceInfo::isMulticastCapable() const |
| 75 | { |
| 76 | return (flags & IFF_MULTICAST) != 0; |
| 77 | } |
| 78 | |
| 79 | inline bool |
Steve DiBenedetto | ca53ac6 | 2014-03-27 19:58:40 -0600 | [diff] [blame] | 80 | NetworkInterfaceInfo::isBroadcastCapable() const |
| 81 | { |
| 82 | return (flags & IFF_BROADCAST) != 0; |
| 83 | } |
| 84 | |
| 85 | inline bool |
Davide Pesavento | 248d6bd | 2014-03-09 10:24:08 +0100 | [diff] [blame] | 86 | NetworkInterfaceInfo::isUp() const |
| 87 | { |
| 88 | return (flags & IFF_UP) != 0; |
| 89 | } |
| 90 | |
| 91 | std::list< shared_ptr<NetworkInterfaceInfo> > |
| 92 | listNetworkInterfaces(); |
| 93 | |
| 94 | } // namespace nfd |
| 95 | |
| 96 | #endif // NFD_CORE_NETWORK_INTERFACE_HPP |