Async  0.18.0
AsyncIpAddress.h
Go to the documentation of this file.
1 
30 #ifndef ASYNC_IP_ADDRESS_INCLUDED
31 #define ASYNC_IP_ADDRESS_INCLUDED
32 
33 
34 /****************************************************************************
35  *
36  * System Includes
37  *
38  ****************************************************************************/
39 
40 #include <netinet/in.h>
41 
42 #include <string>
43 #include <iostream>
44 
45 
46 /****************************************************************************
47  *
48  * Project Includes
49  *
50  ****************************************************************************/
51 
52 
53 
54 /****************************************************************************
55  *
56  * Local Includes
57  *
58  ****************************************************************************/
59 
60 
61 
62 /****************************************************************************
63  *
64  * Forward declarations
65  *
66  ****************************************************************************/
67 
68 
69 
70 /****************************************************************************
71  *
72  * Namespace
73  *
74  ****************************************************************************/
75 
76 namespace Async
77 {
78 
79 /****************************************************************************
80  *
81  * Defines & typedefs
82  *
83  ****************************************************************************/
84 
85 
86 
87 /****************************************************************************
88  *
89  * Exported Global Variables
90  *
91  ****************************************************************************/
92 
93 
94 
95 /****************************************************************************
96  *
97  * Class definitions
98  *
99  ****************************************************************************/
100 
105 {
106  public:
110  typedef struct in_addr Ip4Addr;
111 
115  IpAddress(void);
116 
121  IpAddress(const std::string& addr);
122 
127  IpAddress(const Ip4Addr& addr);
128 
133  IpAddress(const IpAddress& addr) { *this = addr; }
134 
138  ~IpAddress(void) {}
139 
144  Ip4Addr ip4Addr(void) const { return m_addr; }
145 
151  bool isUnicast(void) const;
152 
160  bool isWithinSubet(const std::string& subnet) const;
161 
167  bool isEmpty(void) const { return (m_addr.s_addr == INADDR_NONE); }
168 
172  void clear(void) { m_addr.s_addr = INADDR_NONE; }
173 
178  std::string toString(void) const;
179 
186  {
187  m_addr = rhs.m_addr;
188  return *this;
189  }
190 
197  bool operator==(const IpAddress& rhs) const
198  {
199  return m_addr.s_addr == rhs.m_addr.s_addr;
200  }
201 
208  bool operator!=(const IpAddress& rhs) const
209  {
210  return !(*this == rhs);
211  }
212 
219  bool operator<(const IpAddress& rhs) const
220  {
221  return m_addr.s_addr < rhs.m_addr.s_addr;
222  }
223 
229  friend std::ostream& operator<<(std::ostream& os,
230  const Async::IpAddress& ip);
231 
232  protected:
233 
234  private:
235  Ip4Addr m_addr;
236 
237 }; /* class IpAddress */
238 
239 
240 std::ostream& operator<<(std::ostream& os, const IpAddress& ip);
241 
242 
243 } /* namespace */
244 
245 
246 #endif /* ASYNC_IP_ADDRESS_INCLUDED */
247 
248 
249 
250 /*
251  * This file has not been truncated
252  */
253 
bool operator!=(const IpAddress &rhs) const
Unequality operator.
bool isWithinSubet(const std::string &subnet) const
Check if the IP address is within the given netmask.
bool operator==(const IpAddress &rhs) const
Equality operator.
IpAddress & operator=(const IpAddress &rhs)
Assignment operator.
std::ostream & operator<<(std::ostream &os, const IpAddress &ip)
std::string toString(void) const
Return the string representation of the IP address.
bool isUnicast(void) const
Check if this is a unicast IP address.
Ip4Addr ip4Addr(void) const
Return the IP address in OS specific representation.
void clear(void)
Invalidate the IP address value.
IpAddress(const IpAddress &addr)
Copy contructor.
friend std::ostream & operator<<(std::ostream &os, const Async::IpAddress &ip)
Output stream operator.
IpAddress(void)
Default constructor for the IpAddress class.
struct in_addr Ip4Addr
The type for the OS specific representation of an IP address.
bool isEmpty(void) const
Check if an invalid IP address has been assigned.
~IpAddress(void)
Destructor.
bool operator<(const IpAddress &rhs) const
Less than operator.
A class for representing an IP address in an OS independent way.