00001 /* 00002 * InetAddress.hpp 00003 * 00004 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_INET_ADDRESS_HPP 00017 #define COH_INET_ADDRESS_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include <ostream> 00022 00023 COH_OPEN_NAMESPACE2(coherence,net) 00024 00025 00026 /** 00027 * InetAddress represents an IP address. 00028 * 00029 * @author mf 2008.03.17 00030 */ 00031 class COH_EXPORT InetAddress 00032 : public cloneable_spec<InetAddress> 00033 { 00034 friend class factory<InetAddress>; 00035 00036 // ----- constructors --------------------------------------------------- 00037 00038 protected: 00039 /** 00040 * Manually construct an InetAddress from a network byte ordered array. 00041 * 00042 * It is recommended that the #getByName() method be used in place of 00043 * manual InetAddress construction. 00044 * 00045 * @param vsName the name of the host 00046 * @param vaIP the array representation of the host's IP address. 00047 */ 00048 InetAddress(String::View vsHost, Array<octet_t>::View vaIP); 00049 00050 /** 00051 * Copy Constructor. 00052 */ 00053 InetAddress(const InetAddress&); 00054 00055 00056 // ----- InetAddress interface ------------------------------------------ 00057 00058 public: 00059 /** 00060 * Return the InetAddress for the local machine. 00061 * 00062 * @return the local InetAddress. 00063 */ 00064 static InetAddress::View getLocalHost(); 00065 00066 /** 00067 * Return the InetAddress for the specified machine name. 00068 * 00069 * @param vHost the name or IP of the host to resolve 00070 * 00071 * @return the InetAddress for the specified machine name 00072 */ 00073 static InetAddress::View getByName(String::View vHost); 00074 00075 /** 00076 * Return the hostname associated with this address. 00077 * 00078 * @return the hostname associated with this address 00079 */ 00080 virtual String::View getHostName() const; 00081 00082 /** 00083 * Return the address in textual form. 00084 * 00085 * @return the address in textual form 00086 */ 00087 virtual String::View getHostAddress() const; 00088 00089 /** 00090 * Return the raw IP address, in network byte order, with the highest 00091 * order byte stored at index zero. 00092 * 00093 * @return the raw IP address 00094 */ 00095 virtual Array<octet_t>::View getAddress() const; 00096 00097 00098 // ----- Object interface ----------------------------------------------- 00099 00100 public: 00101 /** 00102 * {@inheritDoc} 00103 */ 00104 virtual void toStream(std::ostream& out) const; 00105 00106 /** 00107 * {@inheritDoc} 00108 */ 00109 virtual bool equals(Object::View that) const; 00110 00111 /** 00112 * {@inheritDoc} 00113 */ 00114 virtual size32_t hashCode() const; 00115 00116 00117 // ---- data members ---------------------------------------------------- 00118 00119 private: 00120 /** 00121 * The hostname or textual IP for the address. 00122 */ 00123 FinalView<String> f_vsHostName; 00124 00125 /** 00126 * The raw IP address. 00127 */ 00128 FinalView<Array<octet_t> > f_vaIP; 00129 }; 00130 00131 COH_CLOSE_NAMESPACE2 00132 00133 #endif // COH_INET_ADDRESS_HPP