InetAddress.h++
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
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 };
00185
00186 #endif // __ccxx_InetAddress_hxx
00187
00188