network.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2023, 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
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/>.
24  **/
25 
26 #ifndef NFD_CORE_NETWORK_HPP
27 #define NFD_CORE_NETWORK_HPP
28 
29 #include <boost/asio/ip/address.hpp>
30 #include <boost/operators.hpp>
31 
32 #include <string_view>
33 
34 namespace nfd {
35 
36 class Network : private boost::equality_comparable<Network>
37 {
38 public:
40 
41  Network(const boost::asio::ip::address& minAddress,
42  const boost::asio::ip::address& maxAddress);
43 
44  bool
45  doesContain(const boost::asio::ip::address& address) const noexcept
46  {
47  return m_minAddress <= address && address <= m_maxAddress;
48  }
49 
50  static const Network&
51  getMaxRangeV4();
52 
53  static const Network&
54  getMaxRangeV6();
55 
56  static bool
57  isValidCidr(std::string_view cidr) noexcept;
58 
59 private: // non-member operators
60  friend bool
61  operator==(const Network& lhs, const Network& rhs) noexcept
62  {
63  return lhs.m_minAddress == rhs.m_minAddress &&
64  lhs.m_maxAddress == rhs.m_maxAddress;
65  }
66 
67  friend std::ostream&
68  operator<<(std::ostream& os, const Network& network);
69 
70  friend std::istream&
71  operator>>(std::istream& is, Network& network);
72 
73 private:
74  boost::asio::ip::address m_minAddress;
75  boost::asio::ip::address m_maxAddress;
76 };
77 
78 std::ostream&
79 operator<<(std::ostream& os, const Network& network);
80 
81 std::istream&
82 operator>>(std::istream& is, Network& network);
83 
84 } // namespace nfd
85 
86 #endif // NFD_CORE_NETWORK_HPP
friend std::istream & operator>>(std::istream &is, Network &network)
Definition: network.cpp:89
static bool isValidCidr(std::string_view cidr) noexcept
Definition: network.cpp:66
static const Network & getMaxRangeV6()
Definition: network.cpp:56
static const Network & getMaxRangeV4()
Definition: network.cpp:48
bool doesContain(const boost::asio::ip::address &address) const noexcept
Definition: network.hpp:45
friend std::ostream & operator<<(std::ostream &os, const Network &network)
Definition: network.cpp:83
friend bool operator==(const Network &lhs, const Network &rhs) noexcept
Definition: network.hpp:61
-status-http-server
Definition: common.hpp:71
std::ostream & operator<<(std::ostream &os, const Network &network)
Definition: network.cpp:83
std::istream & operator>>(std::istream &is, Network &network)
Definition: network.cpp:89