ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
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-2024 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 <[email protected]>
22 */
23
24#ifndef NDN_CXX_NET_NETWORK_ADDRESS_HPP
25#define NDN_CXX_NET_NETWORK_ADDRESS_HPP
26
27#include <cstdint>
28#include <iosfwd>
29
30#include <boost/asio/ip/address.hpp>
31
32namespace ndn::net {
33
34enum class AddressFamily {
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
54{
55public:
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
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
131private:
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
140std::ostream&
141operator<<(std::ostream& os, const NetworkAddress& address);
142
143} // namespace ndn::net
144
145#endif // NDN_CXX_NET_NETWORK_ADDRESS_HPP
Stores one IP address supported by a network interface.
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.
std::ostream & operator<<(std::ostream &os, AddressScope scope)