AsyncIpAddress.h
Go to the documentation of this file.00001
00030 #ifndef ASYNC_IP_ADDRESS_INCLUDED
00031 #define ASYNC_IP_ADDRESS_INCLUDED
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <netinet/in.h>
00041
00042 #include <string>
00043 #include <iostream>
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 namespace Async
00077 {
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00104 class IpAddress
00105 {
00106 public:
00110 typedef struct in_addr Ip4Addr;
00111
00115 IpAddress(void);
00116
00121 IpAddress(const std::string& addr);
00122
00127 IpAddress(const Ip4Addr& addr);
00128
00133 IpAddress(const IpAddress& addr) { *this = addr; }
00134
00138 ~IpAddress(void) {}
00139
00144 Ip4Addr ip4Addr(void) const { return m_addr; }
00145
00151 bool isUnicast(void) const;
00152
00160 bool isWithinSubet(const std::string& subnet) const;
00161
00166 std::string toString(void) const;
00167
00173 IpAddress& operator=(const IpAddress& rhs)
00174 {
00175 m_addr = rhs.m_addr;
00176 return *this;
00177 }
00178
00185 bool operator==(const IpAddress& rhs) const
00186 {
00187 return m_addr.s_addr == rhs.m_addr.s_addr;
00188 }
00189
00196 bool operator!=(const IpAddress& rhs) const
00197 {
00198 return !(*this == rhs);
00199 }
00200
00207 bool operator<(const IpAddress& rhs) const
00208 {
00209 return m_addr.s_addr < rhs.m_addr.s_addr;
00210 }
00211
00217 friend std::ostream& operator<<(std::ostream& os,
00218 const Async::IpAddress& ip);
00219
00220 protected:
00221
00222 private:
00223 Ip4Addr m_addr;
00224
00225 };
00226
00227
00228 std::ostream& operator<<(std::ostream& os, const IpAddress& ip);
00229
00230
00231 }
00232
00233
00234 #endif
00235
00236
00237
00238
00239
00240
00241