InetAddress.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_InetAddress_hxx
00024 #define __ccxx_InetAddress_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/ByteOrder.h++>
00028 #include <commonc++/IOException.h++>
00029 #include <commonc++/String.h++>
00030 
00031 #ifdef CCXX_OS_POSIX
00032 #include <sys/types.h>
00033 #include <netinet/in.h>
00034 #endif
00035 
00036 namespace ccxx {
00037 
00043 class COMMONCPP_API HostNotFoundException : public IOException
00044 {
00045   public:
00046 
00050   HostNotFoundException(String message = String::empty);
00051 
00052   inline virtual void write(std::ostream& stream) const
00053   { _write(stream, "HostNotFoundException"); }
00054 
00055 };
00056 
00061 class COMMONCPP_API InetAddress
00062 {
00063   public:
00064 
00066   InetAddress() throw();
00067 
00075   explicit InetAddress(const String &host);
00076 
00082   explicit InetAddress(uint32_t addr) throw();
00083 
00088   explicit InetAddress(byte_t addr[4]) throw();
00089 
00091   ~InetAddress() throw();
00092 
00097   void setHost(const String &host) throw(HostNotFoundException);
00098 
00103   void setAddress(uint32_t addr) throw();
00104 
00109   inline uint32_t getAddress() const throw()
00110   { return(_addr); }
00111 
00117   char getNetworkClass() const throw();
00118 
00122   bool isMulticast() const throw();
00123 
00127   bool isNonroutable() const throw();
00128 
00131   bool isLinkLocal() const throw();
00132 
00137   String getHost() const throw(HostNotFoundException);
00138 
00144   void resolve() throw(HostNotFoundException);
00145 
00147   inline bool isResolved() const throw()
00148   { return(_resolved); }
00149 
00151   String toString() const;
00152 
00154   String toIPString() const;
00155 
00157   bool operator==(const InetAddress &other) const throw();
00158 
00160   inline bool operator!=(const InetAddress &other) const throw()
00161   { return(!operator==(other)); }
00162 
00164   InetAddress & operator|=(const InetAddress &other) throw();
00165 
00167   InetAddress & operator&=(const InetAddress &other) throw();
00168 
00170   static const InetAddress ANY;
00171 
00172   private:
00173 
00174   bool _fromDotSeparated() throw();
00175 
00176   uint32_t _addr;
00177   mutable String _host;
00178   mutable bool _resolved;
00179 };
00180 
00181 inline std::ostream& operator<<(std::ostream& stream, const InetAddress& a)
00182 { return(stream << a.toString().c_str()); }
00183 
00184 }; // namespace ccxx
00185 
00186 #endif // __ccxx_InetAddress_hxx
00187 
00188 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3