network-address.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2021 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 
24 #ifndef NDN_CXX_NET_NETWORK_ADDRESS_HPP
25 #define NDN_CXX_NET_NETWORK_ADDRESS_HPP
26 
28 
29 #include <boost/asio/ip/address.hpp>
30 
31 namespace ndn {
32 namespace net {
33 
34 enum class AddressFamily {
36  V4,
37  V6,
38 };
39 
40 enum class AddressScope {
41  NOWHERE,
42  HOST,
43  LINK,
44  GLOBAL,
45 };
46 
47 std::ostream&
48 operator<<(std::ostream& os, AddressScope scope);
49 
54 {
55 public:
57  const boost::asio::ip::address& ip,
58  const boost::asio::ip::address& broadcast,
59  uint8_t prefixLength,
60  AddressScope scope,
61  uint32_t flags);
62 
67  getFamily() const
68  {
69  return m_family;
70  }
71 
75  boost::asio::ip::address
76  getIp() const
77  {
78  return m_ip;
79  }
80 
84  boost::asio::ip::address
85  getBroadcast() const
86  {
87  return m_broadcast;
88  }
89 
93  uint8_t
95  {
96  return m_prefixLength;
97  }
98 
103  getScope() const
104  {
105  return m_scope;
106  }
107 
111  uint32_t
112  getFlags() const
113  {
114  return m_flags;
115  }
116 
122  bool
123  isDeprecated() const;
124 
125  friend bool
126  operator<(const NetworkAddress& a, const NetworkAddress& b)
127  {
128  return a.m_ip < b.m_ip;
129  }
130 
131 private:
132  AddressFamily m_family;
133  boost::asio::ip::address m_ip;
134  boost::asio::ip::address m_broadcast;
135  uint8_t m_prefixLength;
136  AddressScope m_scope;
137  uint32_t m_flags; // IFA_F_* (linux/if_addr.h) on Linux; zero on other platforms
138 };
139 
140 std::ostream&
141 operator<<(std::ostream& os, const NetworkAddress& address);
142 
143 } // namespace net
144 } // namespace ndn
145 
146 #endif // NDN_CXX_NET_NETWORK_ADDRESS_HPP
Stores one IP address supported by a network interface.
NetworkAddress(AddressFamily family, const boost::asio::ip::address &ip, const boost::asio::ip::address &broadcast, uint8_t prefixLength, AddressScope scope, uint32_t flags)
uint32_t getFlags() const
Returns a bitset of platform-specific flags enabled on the address.
AddressFamily getFamily() const
Returns the address family.
boost::asio::ip::address getBroadcast() const
Returns the IP broadcast address.
friend bool operator<(const NetworkAddress &a, const NetworkAddress &b)
boost::asio::ip::address getIp() const
Returns the IP address (v4 or v6)
AddressScope getScope() const
Returns the address scope.
bool isDeprecated() const
Returns true if the address is deprecated.
uint8_t getPrefixLength() const
Returns the prefix length.
Common includes and macros used throughout the library.
std::ostream & operator<<(std::ostream &os, AddressScope scope)
Definition: data.cpp:25