Async 1.8.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
76namespace 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
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
184 void setIp(const Ip4Addr& addr) { m_addr = addr; }
185
191 bool setIpFromString(const std::string &str);
192
199 {
200 m_addr = rhs.m_addr;
201 return *this;
202 }
203
210 bool operator==(const IpAddress& rhs) const
211 {
212 return m_addr.s_addr == rhs.m_addr.s_addr;
213 }
214
221 bool operator!=(const IpAddress& rhs) const
222 {
223 return !(*this == rhs);
224 }
225
232 bool operator<(const IpAddress& rhs) const
233 {
234 return m_addr.s_addr < rhs.m_addr.s_addr;
235 }
236
242 friend std::ostream& operator<<(std::ostream& os,
243 const Async::IpAddress& ip);
244
250 friend std::istream& operator>>(std::istream& is,
251 Async::IpAddress& ip);
252
253 protected:
254
255 private:
256 Ip4Addr m_addr;
257
258}; /* class IpAddress */
259
260
261std::ostream& operator<<(std::ostream& os, const IpAddress& ip);
262std::istream& operator>>(std::istream& is, IpAddress& ip);
263
264
265} /* namespace */
266
267
268#endif /* ASYNC_IP_ADDRESS_INCLUDED */
269
270
271
272/*
273 * This file has not been truncated
274 */
275
A class for representing an IP address in an OS independent way.
Ip4Addr ip4Addr(void) const
Return the IP address in OS specific representation.
IpAddress(const IpAddress &addr)
Copy contructor.
struct in_addr Ip4Addr
The type for the OS specific representation of an IP address.
bool isWithinSubet(const std::string &subnet) const
Check if the IP address is within the given netmask.
std::string toString(void) const
Return the string representation of the IP address.
~IpAddress(void)
Destructor.
bool setIpFromString(const std::string &str)
Set the IP address from a string.
friend std::ostream & operator<<(std::ostream &os, const Async::IpAddress &ip)
Output stream operator.
void clear(void)
Invalidate the IP address value.
bool operator!=(const IpAddress &rhs) const
Unequality operator.
bool isUnicast(void) const
Check if this is a unicast IP address.
IpAddress(const Ip4Addr &addr)
Constructor for the IpAddress class.
friend std::istream & operator>>(std::istream &is, Async::IpAddress &ip)
Input stream operator.
IpAddress(void)
Default constructor for the IpAddress class.
IpAddress(const std::string &addr)
Constructor for the IpAddress class.
bool operator<(const IpAddress &rhs) const
Less than operator.
void setIp(const Ip4Addr &addr)
Set the IP address.
bool operator==(const IpAddress &rhs) const
Equality operator.
IpAddress & operator=(const IpAddress &rhs)
Assignment operator.
bool isEmpty(void) const
Check if an invalid IP address has been assigned.
Namespace for the asynchronous programming classes.
std::istream & operator>>(std::istream &is, IpAddress &ip)
std::ostream & operator<<(std::ostream &os, const IpAddress &ip)