blob: 632a30f08de2d3a949668b425acb2d4af8b590e5 [file] [log] [blame]
Davide Pesavento2bf35a62017-04-02 00:41:06 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2017 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 *
21 * @author Davide Pesavento <davide.pesavento@lip6.fr>
22 */
23
Junxiao Shi25467942017-06-30 02:53:14 +000024#ifndef NDN_NET_NETWORK_ADDRESS_HPP
25#define NDN_NET_NETWORK_ADDRESS_HPP
Davide Pesavento2bf35a62017-04-02 00:41:06 -040026
27#include "network-monitor.hpp"
28
29#include <boost/asio/ip/address.hpp>
30
31namespace ndn {
Junxiao Shi25467942017-06-30 02:53:14 +000032namespace net {
Davide Pesavento2bf35a62017-04-02 00:41:06 -040033
34enum class AddressFamily {
35 UNSPECIFIED,
36 V4,
37 V6,
38};
39
40enum class AddressScope {
41 NOWHERE,
42 HOST,
43 LINK,
44 GLOBAL,
45};
46
47std::ostream&
48operator<<(std::ostream& os, AddressScope scope);
49
50/**
51 * @brief Stores one IP address supported by a network interface.
52 */
53class NetworkAddress
54{
55public: // getters
56 /** @brief Returns the address family
57 */
58 AddressFamily
59 getFamily() const
60 {
61 return m_family;
62 }
63
64 /** @brief Returns the IP address (v4 or v6)
65 */
66 boost::asio::ip::address
67 getIp() const
68 {
69 return m_ip;
70 }
71
72 /** @brief Returns the IP broadcast address
73 */
74 boost::asio::ip::address
75 getBroadcast() const
76 {
77 return m_broadcast;
78 }
79
80 /** @brief Returns a bitset of platform-specific flags enabled on the address
81 */
82 uint32_t
83 getFlags() const
84 {
85 return m_flags;
86 }
87
88 /** @brief Returns the address scope
89 */
90 AddressScope
91 getScope() const
92 {
93 return m_scope;
94 }
95
96 /** @brief Returns the prefix length
97 */
98 uint8_t
99 getPrefixLength() const
100 {
101 return m_prefixLength;
102 }
103
104 friend bool
105 operator<(const NetworkAddress& a, const NetworkAddress& b)
106 {
107 return a.m_ip < b.m_ip;
108 }
109
110private: // constructor
111 NetworkAddress();
112
113private:
114 friend class NetworkMonitor::Impl;
115
116 AddressFamily m_family;
117 boost::asio::ip::address m_ip;
118 boost::asio::ip::address m_broadcast;
119 uint32_t m_flags; // IFA_F_* in if_addr.h
120 AddressScope m_scope;
121 uint8_t m_prefixLength;
122};
123
124std::ostream&
125operator<<(std::ostream& os, const NetworkAddress& address);
126
Junxiao Shi25467942017-06-30 02:53:14 +0000127} // namespace net
Davide Pesavento2bf35a62017-04-02 00:41:06 -0400128} // namespace ndn
129
Junxiao Shi25467942017-06-30 02:53:14 +0000130#endif // NDN_NET_NETWORK_ADDRESS_HPP