00001 /* 00002 * InetAddress.hpp 00003 * 00004 * Copyright (c) 2000, 2019, 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 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 vsHost); 00074 00075 /** 00076 * Given the name of a host, returns an array of its IP addresses, 00077 * based on the configured name service on the system. 00078 * 00079 * If the host is NULL then an InetAddress representing an address 00080 * of the loopback interface is returned. 00081 * 00082 * @param vsHost the name of the host, or NULL 00083 * 00084 * @return an array of all the IP addresses for a given host name 00085 * 00086 * @exception UnknownHostException if no IP address for the 00087 * vsHost could be found. 00088 * 00089 * @since 12.2.1 00090 */ 00091 static ObjectArray::Handle getAllByName(String::View vsHost); 00092 00093 /** 00094 * Returns the loopback address. 00095 * 00096 * @return the InetAddress loopback instance 00097 * 00098 * @since 12.2.1 00099 */ 00100 static InetAddress::View getLoopbackAddress(); 00101 00102 /** 00103 * Return the hostname associated with this address. 00104 * 00105 * @return the hostname associated with this address 00106 */ 00107 virtual String::View getHostName() const; 00108 00109 /** 00110 * Return the address in textual form. 00111 * 00112 * @return the address in textual form 00113 */ 00114 virtual String::View getHostAddress() const; 00115 00116 /** 00117 * Return the raw IP address, in network byte order, with the highest 00118 * order byte stored at index zero. 00119 * 00120 * @return the raw IP address 00121 */ 00122 virtual Array<octet_t>::View getAddress() const; 00123 00124 00125 // ----- Object interface ----------------------------------------------- 00126 00127 public: 00128 /** 00129 * {@inheritDoc} 00130 */ 00131 virtual TypedHandle<const String> toString() const; 00132 00133 /** 00134 * {@inheritDoc} 00135 */ 00136 virtual bool equals(Object::View that) const; 00137 00138 /** 00139 * {@inheritDoc} 00140 */ 00141 virtual size32_t hashCode() const; 00142 00143 00144 // ---- data members ---------------------------------------------------- 00145 00146 private: 00147 /** 00148 * The hostname or textual IP for the address. 00149 */ 00150 FinalView<String> f_vsHostName; 00151 00152 /** 00153 * The raw IP address. 00154 */ 00155 FinalView<Array<octet_t> > f_vaIP; 00156 }; 00157 00158 COH_CLOSE_NAMESPACE2 00159 00160 #endif // COH_INET_ADDRESS_HPP