Async  1.5.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 
185  bool setIpFromString(const std::string &str);
186 
193  {
194  m_addr = rhs.m_addr;
195  return *this;
196  }
197 
204  bool operator==(const IpAddress& rhs) const
205  {
206  return m_addr.s_addr == rhs.m_addr.s_addr;
207  }
208 
215  bool operator!=(const IpAddress& rhs) const
216  {
217  return !(*this == rhs);
218  }
219 
226  bool operator<(const IpAddress& rhs) const
227  {
228  return m_addr.s_addr < rhs.m_addr.s_addr;
229  }
230 
236  friend std::ostream& operator<<(std::ostream& os,
237  const Async::IpAddress& ip);
238 
244  friend std::istream& operator>>(std::istream& is,
245  Async::IpAddress& ip);
246 
247  protected:
248 
249  private:
250  Ip4Addr m_addr;
251 
252 }; /* class IpAddress */
253 
254 
255 std::ostream& operator<<(std::ostream& os, const IpAddress& ip);
256 std::istream& operator>>(std::istream& is, IpAddress& ip);
257 
258 
259 } /* namespace */
260 
261 
262 #endif /* ASYNC_IP_ADDRESS_INCLUDED */
263 
264 
265 
266 /*
267  * This file has not been truncated
268  */
269 
bool operator<(const IpAddress &rhs) const
Less than operator.
IpAddress & operator=(const IpAddress &rhs)
Assignment operator.
friend std::istream & operator>>(std::istream &is, Async::IpAddress &ip)
Input stream operator.
std::ostream & operator<<(std::ostream &os, const IpAddress &ip)
bool isUnicast(void) const
Check if this is a unicast IP address.
bool isWithinSubet(const std::string &subnet) const
Check if the IP address is within the given netmask.
Ip4Addr ip4Addr(void) const
Return the IP address in OS specific representation.
bool operator==(const IpAddress &rhs) const
Equality operator.
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.
~IpAddress(void)
Destructor.
bool isEmpty(void) const
Check if an invalid IP address has been assigned.
bool operator!=(const IpAddress &rhs) const
Unequality operator.
Namespace for the asynchronous programming classes.
std::string toString(void) const
Return the string representation of the IP address.
A class for representing an IP address in an OS independent way.
bool setIpFromString(const std::string &str)
Set the IP address from a string.
std::istream & operator>>(std::istream &is, IpAddress &ip)