INet4Address.hh
Go to the documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Socket_Protocols_INet_INet4Address_
00027 #define HH_SENF_Socket_Protocols_INet_INet4Address_ 1
00028
00029
00030 #include <iostream>
00031 #include <string>
00032 #include <boost/cstdint.hpp>
00033 #include <boost/array.hpp>
00034 #include <boost/operators.hpp>
00035 #include <senf/Utils/safe_bool.hh>
00036 #include <senf/Utils/Tags.hh>
00037
00038
00039
00040
00041 namespace senf {
00042
00088 class INet4Address
00089 : public boost::array<boost::uint8_t,4>,
00090 public comparable_safe_bool<INet4Address>
00091 {
00092 public:
00093
00094
00095
00096 typedef uint32_t address_type;
00097 typedef uint32_t inaddr_type;
00098
00099 static INet4Address const None;
00100 static INet4Address const Loopback;
00101 static INet4Address const Broadcast;
00102
00103
00105
00106
00107 INet4Address();
00108 explicit INet4Address(senf::NoInit_t);
00109 explicit INet4Address(address_type value);
00111
00112 static INet4Address from_string(std::string const & s);
00114
00126 template <class InputIterator>
00127 static INet4Address from_data(InputIterator i);
00129
00132 static INet4Address from_inaddr(inaddr_type v);
00134
00138
00139
00141
00142
00143 bool local() const;
00144
00146 bool loopback() const;
00147
00149 bool multicast() const;
00150
00153 bool broadcast() const;
00154 bool boolean_test() const;
00155
00156 inaddr_type inaddr() const;
00157
00159 address_type address() const;
00160
00163
00164
00165 private:
00166 enum InAddr_t { IsInAddr };
00167 INet4Address(inaddr_type addr, InAddr_t);
00168 inaddr_type & iref();
00169 inaddr_type iref() const;
00170 };
00171
00175 std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
00176
00182 std::istream & operator>>(std::istream & os, INet4Address & addr);
00183
00207 template <boost::uint32_t address, unsigned prefix_len>
00208 class CheckINet4Network
00209 {
00210 public:
00211 static bool match(INet4Address const & addr);
00212 };
00213
00218 class INet4Network
00219 : public boost::equality_comparable<INet4Network>,
00220 public comparable_safe_bool<INet4Network>
00221 {
00222 public:
00223
00225
00226
00227 INet4Network();
00228 INet4Network(INet4Address const & address, unsigned prefix_len);
00230 explicit INet4Network(std::string const & s);
00231
00232
00233
00234
00235 INet4Address const & address() const;
00236 unsigned prefix_len() const;
00237
00238 bool boolean_test() const;
00239 bool operator==(INet4Network const & other) const;
00241
00242 bool match(INet4Address const & addr) const;
00243 bool match(INet4Network const & net) const;
00244
00247 INet4Address host(boost::uint32_t number);
00248
00255 INet4Network subnet(boost::uint32_t net, unsigned prefix_len);
00257
00267 protected:
00268
00269 private:
00270 boost::uint32_t mask() const;
00271
00272 unsigned prefix_len_;
00273 INet4Address address_;
00274 };
00275
00279 std::ostream & operator<<(std::ostream & os, INet4Network const & addr);
00280
00287 std::istream & operator>>(std::istream & is, INet4Network & addr);
00288
00289 }
00290
00291
00292 #include "INet4Address.cci"
00293 #include "INet4Address.ct"
00294 #include "INet4Address.cti"
00295 #endif
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306