mavtables  0.2.1
MAVLink router and firewall.
IPAddress.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2017-2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef IPADDRESS_HPP_
19 #define IPADDRESS_HPP_
20 
21 
22 #include <ostream>
23 #include <stdexcept>
24 #include <string>
25 
26 #include "DNSLookupError.hpp"
27 
28 
29 /** An IP address with optional port number.
30  */
31 class IPAddress
32 {
33  public:
34  /** Copy constructor.
35  *
36  * \param other IP address to copy from.
37  */
38  IPAddress(const IPAddress &other) = default;
39  /** Move constructor.
40  *
41  * \param other IP address to move from.
42  */
43  IPAddress(IPAddress &&other) = default;
44  IPAddress(const IPAddress &other, unsigned int port);
45  IPAddress(unsigned long address, unsigned int port = 0);
46  IPAddress(std::string address);
47  unsigned long address() const;
48  unsigned int port() const;
49  /** Assignment operator.
50  *
51  * \param other IP address to copy from.
52  */
53  IPAddress &operator=(const IPAddress &other) = default;
54  /** Assignment operator (by move semantics).
55  *
56  * \param other IP address to move from.
57  */
58  IPAddress &operator=(IPAddress &&other) = default;
59 
60  friend std::ostream &operator<<(
61  std::ostream &os, const IPAddress &ipaddress);
62 
63  private:
64  unsigned long address_;
65  unsigned int port_;
66  void construct_(unsigned long address, unsigned int port);
67 };
68 
69 
70 bool operator==(const IPAddress &lhs, const IPAddress &rhs);
71 bool operator!=(const IPAddress &lhs, const IPAddress &rhs);
72 bool operator<(const IPAddress &lhs, const IPAddress &rhs);
73 bool operator>(const IPAddress &lhs, const IPAddress &rhs);
74 bool operator<=(const IPAddress &lhs, const IPAddress &rhs);
75 bool operator>=(const IPAddress &lhs, const IPAddress &rhs);
76 std::ostream &operator<<(std::ostream &os, const IPAddress &ipaddress);
77 
78 
79 IPAddress dnslookup(const std::string &url);
80 
81 
82 #endif // IPADDRESS_HPP_
unsigned int port() const
Definition: IPAddress.cpp:215
IPAddress & operator=(const IPAddress &other)=default
friend std::ostream & operator<<(std::ostream &os, const IPAddress &ipaddress)
Definition: IPAddress.cpp:340
IPAddress(const IPAddress &other)=default
std::ostream & operator<<(std::ostream &os, const Action &action)
Definition: Action.cpp:188
bool operator==(const Action &lhs, const Action &rhs)
Definition: Action.cpp:154
unsigned long address() const
Definition: IPAddress.cpp:205
bool operator<=(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:297
bool operator!=(const Action &lhs, const Action &rhs)
Definition: Action.cpp:168
IPAddress dnslookup(const std::string &url)
Definition: IPAddress.cpp:371
bool operator>=(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:313
bool operator>(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:280
bool operator<(const IPAddress &lhs, const IPAddress &rhs)
Definition: IPAddress.cpp:263