diff options
author | Jeremy C. Reed <jreed@ISC.org> | 2011-03-14 16:47:19 +0100 |
---|---|---|
committer | Jeremy C. Reed <jreed@ISC.org> | 2011-03-14 16:47:19 +0100 |
commit | ba9ed9d67285288e425e9fe9ebddf99bcda69d8a (patch) | |
tree | 342a3a7b9b25e2828036230e9cb692d7d4485e57 /src/lib/asiolink/io_address.h | |
parent | [jreed-doxygen] remove wrong documentation (diff) | |
parent | [master] add two more testdata files to tarball (diff) | |
download | kea-ba9ed9d67285288e425e9fe9ebddf99bcda69d8a.tar.xz kea-ba9ed9d67285288e425e9fe9ebddf99bcda69d8a.zip |
[jreed-doxygen]Merge branch 'master' into jreed-doxygen
Also manually fixed some conflicts.
Diffstat (limited to 'src/lib/asiolink/io_address.h')
-rw-r--r-- | src/lib/asiolink/io_address.h | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/src/lib/asiolink/io_address.h b/src/lib/asiolink/io_address.h new file mode 100644 index 0000000000..53c1a7a13a --- /dev/null +++ b/src/lib/asiolink/io_address.h @@ -0,0 +1,123 @@ +// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +#ifndef __IO_ADDRESS_H +#define __IO_ADDRESS_H 1 + +// IMPORTANT NOTE: only very few ASIO headers files can be included in +// this file. In particular, asio.hpp should never be included here. +// See the description of the namespace below. +#include <unistd.h> // for some network system calls +#include <asio/ip/address.hpp> + +#include <functional> +#include <string> + +#include <exceptions/exceptions.h> + +namespace asiolink { + +/// \brief The \c IOAddress class represents an IP addresses (version +/// agnostic) +/// +/// This class is a wrapper for the ASIO \c ip::address class. +class IOAddress { +public: + /// + /// \name Constructors and Destructor + /// + /// This class is copyable. We use default versions of copy constructor + /// and the assignment operator. + /// We use the default destructor. + //@{ + /// \brief Constructor from string. + /// + /// This constructor converts a textual representation of IPv4 and IPv6 + /// addresses into an IOAddress object. + /// If \c address_str is not a valid representation of any type of + /// address, an exception of class \c IOError will be thrown. + /// This constructor allocates memory for the object, and if that fails + /// a corresponding standard exception will be thrown. + /// + /// \param address_str Textual representation of address. + IOAddress(const std::string& address_str); + + /// \brief Constructor from an ASIO \c ip::address object. + /// + /// This constructor is intended to be used within the wrapper + /// implementation; user applications of the wrapper API won't use it. + /// + /// This constructor never throws an exception. + /// + /// \param asio_address The ASIO \c ip::address to be converted. + IOAddress(const asio::ip::address& asio_address); + //@} + + /// \brief Convert the address to a string. + /// + /// This method is basically expected to be exception free, but + /// generating the string will involve resource allocation, + /// and if it fails the corresponding standard exception will be thrown. + /// + /// \return A string representation of the address. + std::string toText() const; + + /// \brief Returns the address family + /// + /// \return AF_INET for IPv4 or AF_INET6 for IPv6. + short getFamily() const; + + /// \brief Compare addresses for equality + /// + /// \param other Address to compare against. + /// + /// \return true if addresses are equal, false if not. + bool equals(const IOAddress& other) const { + return (asio_address_ == other.asio_address_); + } + + /// \brief Compare addresses for equality + /// + /// \param other Address to compare against. + /// + /// \return true if addresses are equal, false if not. + bool operator==(const IOAddress& other) const { + return equals(other); + } + + // \brief Compare addresses for inequality + /// + /// \param other Address to compare against. + /// + /// \return false if addresses are equal, true if not. + bool nequals(const IOAddress& other) const { + return (!equals(other)); + } + + // \brief Compare addresses for inequality + /// + /// \param other Address to compare against. + /// + /// \return false if addresses are equal, true if not. + bool operator!=(const IOAddress& other) const { + return (nequals(other)); + } + + +private: + asio::ip::address asio_address_; +}; + +} // asiolink +#endif // __IO_ADDRESS_H |