#include <boost/operators.hpp>
#include "../../../Utils/safe_bool.hh"
#include "../../../Utils/Tags.hh"
+#include "../AddressExceptions.hh"
//#include "INet4Address.mpp"
///////////////////////////////hh.p////////////////////////////////////////
INet4Address represents a simple IP address. It is modelled as a fixed-size
container/sequence of 4 bytes.
+ The following statements all create the same INet4 address <code>211.194.177.160</code>
+ \code
+ // Used to construct constant INet4 addresses
+ INet4Address(0xD3C2B1A0)
+
+ // Construct an INet4 address from it's string representation. All the standard address
+ // representations are supported
+ INet4Address::from_string("211.194.177.160")
+ INet4Address::from_string("211.12759456")
+
+ // Construct an INet4 address from raw data. 'from_data' takes an arbitrary iterator (e.g. a
+ // pointer) as argument. Here we use a fixed array but normally you will need this to build
+ // an INet4 address in a packet parser
+ char rawBytes[] = { 0xD3, 0xC2, 0xB1, 0xA0 };
+ INet4Address::from_data(rawBytes)
+
+ // Construct an INet4 address from the standard POSIX representation: a 32-bit integer in
+ // network byte oder. This is used to interface with POSIX routines
+ struct sockaddr_in saddr = ...;
+ INet4Address::from_inaddr(saddr.sin_addr.s_addr)
+ \endcode
+
+ Since INet4Address is based on \c boost::array, you can access the raw data bytes of the
+ address (in network byte order) using \c begin(), \c end() or \c operator[]
+ \code
+ INet4Address ina = ...;
+ Packet::iterator i = ...;
+ std::copy(ina.begin(), ina.end(), i); // Copies 4 bytes
+ \endcode
+
\see CheckINet4Network \n INet4Network
\implementation We awkwardly need to use static named constructors (<tt>from_</tt> members)
\attention This call may block if \a s represents a
hostname which must be looked up via some network
protocol like DNS or NIS
- \throws SyntaxException if the address cannot be
+ \throws AddressSyntaxException if the address cannot be
converted for some reason
\param[in] s Address literal or hostname */
////@}
- /** \brief Base-class for INet4Address exceptions */
- struct AddressException : public std::exception {};
-
- /** \brief Invalid INet4 address syntax */
- struct SyntaxException : public AddressException
- { virtual char const * what() const throw()
- { return "invalid INet4 address syntax"; } };
-
- /** \brief Resolver failure */
- struct UnknownHostnameException : public AddressException
- { virtual char const * what() const throw()
- { return "failed to resolve INet4 hostname"; } };
-
private:
enum InAddr_t { IsInAddr };
INet4Address(inaddr_type addr, InAddr_t);