author | xdono |
Thu, 02 Oct 2008 19:58:32 -0700 | |
changeset 1247 | b4c26443dee5 |
parent 1152 | 29d6145d1097 |
child 5180 | 8161f879d704 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package java.net; |
|
27 |
||
28 |
import java.util.Enumeration; |
|
29 |
import java.util.NoSuchElementException; |
|
30 |
import sun.security.action.*; |
|
31 |
import java.security.AccessController; |
|
32 |
||
33 |
/** |
|
34 |
* This class represents a Network Interface made up of a name, |
|
35 |
* and a list of IP addresses assigned to this interface. |
|
36 |
* It is used to identify the local interface on which a multicast group |
|
37 |
* is joined. |
|
38 |
* |
|
39 |
* Interfaces are normally known by names such as "le0". |
|
40 |
* |
|
41 |
* @since 1.4 |
|
42 |
*/ |
|
43 |
public final class NetworkInterface { |
|
44 |
private String name; |
|
45 |
private String displayName; |
|
46 |
private int index; |
|
47 |
private InetAddress addrs[]; |
|
48 |
private InterfaceAddress bindings[]; |
|
49 |
private NetworkInterface childs[]; |
|
50 |
private NetworkInterface parent = null; |
|
51 |
private boolean virtual = false; |
|
52 |
||
53 |
static { |
|
54 |
AccessController.doPrivileged(new LoadLibraryAction("net")); |
|
55 |
init(); |
|
56 |
} |
|
57 |
||
58 |
/** |
|
59 |
* Returns an NetworkInterface object with index set to 0 and name to null. |
|
60 |
* Setting such an interface on a MulticastSocket will cause the |
|
61 |
* kernel to choose one interface for sending multicast packets. |
|
62 |
* |
|
63 |
*/ |
|
64 |
NetworkInterface() { |
|
65 |
} |
|
66 |
||
67 |
NetworkInterface(String name, int index, InetAddress[] addrs) { |
|
68 |
this.name = name; |
|
69 |
this.index = index; |
|
70 |
this.addrs = addrs; |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Get the name of this network interface. |
|
75 |
* |
|
76 |
* @return the name of this network interface |
|
77 |
*/ |
|
78 |
public String getName() { |
|
79 |
return name; |
|
80 |
} |
|
81 |
||
82 |
/** |
|
83 |
* Convenience method to return an Enumeration with all or a |
|
84 |
* subset of the InetAddresses bound to this network interface. |
|
85 |
* <p> |
|
86 |
* If there is a security manager, its <code>checkConnect</code> |
|
87 |
* method is called for each InetAddress. Only InetAddresses where |
|
88 |
* the <code>checkConnect</code> doesn't throw a SecurityException |
|
89 |
* will be returned in the Enumeration. |
|
90 |
* @return an Enumeration object with all or a subset of the InetAddresses |
|
91 |
* bound to this network interface |
|
92 |
*/ |
|
93 |
public Enumeration<InetAddress> getInetAddresses() { |
|
94 |
||
95 |
class checkedAddresses implements Enumeration<InetAddress> { |
|
96 |
||
97 |
private int i=0, count=0; |
|
98 |
private InetAddress local_addrs[]; |
|
99 |
||
100 |
checkedAddresses() { |
|
101 |
local_addrs = new InetAddress[addrs.length]; |
|
102 |
||
103 |
SecurityManager sec = System.getSecurityManager(); |
|
104 |
for (int j=0; j<addrs.length; j++) { |
|
105 |
try { |
|
106 |
if (sec != null) { |
|
107 |
sec.checkConnect(addrs[j].getHostAddress(), -1); |
|
108 |
} |
|
109 |
local_addrs[count++] = addrs[j]; |
|
110 |
} catch (SecurityException e) { } |
|
111 |
} |
|
112 |
||
113 |
} |
|
114 |
||
115 |
public InetAddress nextElement() { |
|
116 |
if (i < count) { |
|
117 |
return local_addrs[i++]; |
|
118 |
} else { |
|
119 |
throw new NoSuchElementException(); |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
public boolean hasMoreElements() { |
|
124 |
return (i < count); |
|
125 |
} |
|
126 |
} |
|
127 |
return new checkedAddresses(); |
|
128 |
||
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* Get a List of all or a subset of the <code>InterfaceAddresses</code> |
|
133 |
* of this network interface. |
|
134 |
* <p> |
|
135 |
* If there is a security manager, its <code>checkConnect</code> |
|
136 |
* method is called with the InetAddress for each InterfaceAddress. |
|
137 |
* Only InterfaceAddresses where the <code>checkConnect</code> doesn't throw |
|
138 |
* a SecurityException will be returned in the List. |
|
139 |
* |
|
140 |
* @return a <code>List</code> object with all or a subset of the |
|
141 |
* InterfaceAddresss of this network interface |
|
142 |
* @since 1.6 |
|
143 |
*/ |
|
144 |
public java.util.List<InterfaceAddress> getInterfaceAddresses() { |
|
145 |
java.util.List<InterfaceAddress> lst = new java.util.ArrayList<InterfaceAddress>(1); |
|
146 |
SecurityManager sec = System.getSecurityManager(); |
|
147 |
for (int j=0; j<bindings.length; j++) { |
|
148 |
try { |
|
149 |
if (sec != null) { |
|
150 |
sec.checkConnect(bindings[j].getAddress().getHostAddress(), -1); |
|
151 |
} |
|
152 |
lst.add(bindings[j]); |
|
153 |
} catch (SecurityException e) { } |
|
154 |
} |
|
155 |
return lst; |
|
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* Get an Enumeration with all the subinterfaces (also known as virtual |
|
160 |
* interfaces) attached to this network interface. |
|
161 |
* <p> |
|
162 |
* For instance eth0:1 will be a subinterface to eth0. |
|
163 |
* |
|
164 |
* @return an Enumeration object with all of the subinterfaces |
|
165 |
* of this network interface |
|
166 |
* @since 1.6 |
|
167 |
*/ |
|
168 |
public Enumeration<NetworkInterface> getSubInterfaces() { |
|
169 |
class subIFs implements Enumeration<NetworkInterface> { |
|
170 |
||
171 |
private int i=0; |
|
172 |
||
173 |
subIFs() { |
|
174 |
} |
|
175 |
||
176 |
public NetworkInterface nextElement() { |
|
177 |
if (i < childs.length) { |
|
178 |
return childs[i++]; |
|
179 |
} else { |
|
180 |
throw new NoSuchElementException(); |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
public boolean hasMoreElements() { |
|
185 |
return (i < childs.length); |
|
186 |
} |
|
187 |
} |
|
188 |
return new subIFs(); |
|
189 |
||
190 |
} |
|
191 |
||
192 |
/** |
|
193 |
* Returns the parent NetworkInterface of this interface if this is |
|
194 |
* a subinterface, or <code>null</code> if it is a physical |
|
195 |
* (non virtual) interface or has no parent. |
|
196 |
* |
|
197 |
* @return The <code>NetworkInterface</code> this interface is attached to. |
|
198 |
* @since 1.6 |
|
199 |
*/ |
|
200 |
public NetworkInterface getParent() { |
|
201 |
return parent; |
|
202 |
} |
|
203 |
||
204 |
/** |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
205 |
* Returns the index of this network interface. The index is an integer greater |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
206 |
* or equal to zero, or {@code -1} for unknown. This is a system specific value |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
207 |
* and interfaces with the same name can have different indexes on different |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
208 |
* machines. |
2 | 209 |
* |
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
210 |
* @return the index of this network interface or {@code -1} if the index is |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
211 |
* unknown |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
212 |
* @see #getByIndex(int) |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
213 |
* @since 1.7 |
2 | 214 |
*/ |
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
215 |
public int getIndex() { |
2 | 216 |
return index; |
217 |
} |
|
218 |
||
219 |
/** |
|
220 |
* Get the display name of this network interface. |
|
221 |
* A display name is a human readable String describing the network |
|
222 |
* device. |
|
223 |
* |
|
224 |
* @return the display name of this network interface, |
|
225 |
* or null if no display name is available. |
|
226 |
*/ |
|
227 |
public String getDisplayName() { |
|
228 |
return displayName; |
|
229 |
} |
|
230 |
||
231 |
/** |
|
232 |
* Searches for the network interface with the specified name. |
|
233 |
* |
|
234 |
* @param name |
|
235 |
* The name of the network interface. |
|
236 |
* |
|
237 |
* @return A <tt>NetworkInterface</tt> with the specified name, |
|
238 |
* or <tt>null</tt> if there is no network interface |
|
239 |
* with the specified name. |
|
240 |
* |
|
241 |
* @throws SocketException |
|
242 |
* If an I/O error occurs. |
|
243 |
* |
|
244 |
* @throws NullPointerException |
|
245 |
* If the specified name is <tt>null</tt>. |
|
246 |
*/ |
|
247 |
public static NetworkInterface getByName(String name) throws SocketException { |
|
248 |
if (name == null) |
|
249 |
throw new NullPointerException(); |
|
250 |
return getByName0(name); |
|
251 |
} |
|
252 |
||
253 |
/** |
|
254 |
* Get a network interface given its index. |
|
255 |
* |
|
256 |
* @param index an integer, the index of the interface |
|
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
257 |
* @return the NetworkInterface obtained from its index, or {@code null} if |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
258 |
* there is no interface with such an index on the system |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
259 |
* @throws SocketException if an I/O error occurs. |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
260 |
* @throws IllegalArgumentException if index has a negative value |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
261 |
* @see #getIndex() |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
262 |
* @since 1.7 |
2 | 263 |
*/ |
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
264 |
public static NetworkInterface getByIndex(int index) throws SocketException { |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
265 |
if (index < 0) |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
266 |
throw new IllegalArgumentException("Interface index can't be negative"); |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
267 |
return getByIndex0(index); |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
268 |
} |
2 | 269 |
|
270 |
/** |
|
271 |
* Convenience method to search for a network interface that |
|
272 |
* has the specified Internet Protocol (IP) address bound to |
|
273 |
* it. |
|
274 |
* <p> |
|
275 |
* If the specified IP address is bound to multiple network |
|
276 |
* interfaces it is not defined which network interface is |
|
277 |
* returned. |
|
278 |
* |
|
279 |
* @param addr |
|
280 |
* The <tt>InetAddress</tt> to search with. |
|
281 |
* |
|
282 |
* @return A <tt>NetworkInterface</tt> |
|
283 |
* or <tt>null</tt> if there is no network interface |
|
284 |
* with the specified IP address. |
|
285 |
* |
|
286 |
* @throws SocketException |
|
287 |
* If an I/O error occurs. |
|
288 |
* |
|
289 |
* @throws NullPointerException |
|
290 |
* If the specified address is <tt>null</tt>. |
|
291 |
*/ |
|
292 |
public static NetworkInterface getByInetAddress(InetAddress addr) throws SocketException { |
|
293 |
if (addr == null) |
|
294 |
throw new NullPointerException(); |
|
295 |
return getByInetAddress0(addr); |
|
296 |
} |
|
297 |
||
298 |
/** |
|
299 |
* Returns all the interfaces on this machine. Returns null if no |
|
300 |
* network interfaces could be found on this machine. |
|
301 |
* |
|
302 |
* NOTE: can use getNetworkInterfaces()+getInetAddresses() |
|
303 |
* to obtain all IP addresses for this node |
|
304 |
* |
|
305 |
* @return an Enumeration of NetworkInterfaces found on this machine |
|
306 |
* @exception SocketException if an I/O error occurs. |
|
307 |
*/ |
|
308 |
||
309 |
public static Enumeration<NetworkInterface> getNetworkInterfaces() |
|
310 |
throws SocketException { |
|
311 |
final NetworkInterface[] netifs = getAll(); |
|
312 |
||
313 |
// specified to return null if no network interfaces |
|
314 |
if (netifs == null) |
|
315 |
return null; |
|
316 |
||
317 |
return new Enumeration<NetworkInterface>() { |
|
318 |
private int i = 0; |
|
319 |
public NetworkInterface nextElement() { |
|
320 |
if (netifs != null && i < netifs.length) { |
|
321 |
NetworkInterface netif = netifs[i++]; |
|
322 |
return netif; |
|
323 |
} else { |
|
324 |
throw new NoSuchElementException(); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
public boolean hasMoreElements() { |
|
329 |
return (netifs != null && i < netifs.length); |
|
330 |
} |
|
331 |
}; |
|
332 |
} |
|
333 |
||
334 |
private native static NetworkInterface[] getAll() |
|
335 |
throws SocketException; |
|
336 |
||
337 |
private native static NetworkInterface getByName0(String name) |
|
338 |
throws SocketException; |
|
339 |
||
1097
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
340 |
private native static NetworkInterface getByIndex0(int index) |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
341 |
throws SocketException; |
af4930f761df
6717876: Make java.net.NetworkInterface.getIndex() public
jccollet
parents:
715
diff
changeset
|
342 |
|
2 | 343 |
private native static NetworkInterface getByInetAddress0(InetAddress addr) |
344 |
throws SocketException; |
|
345 |
||
346 |
/** |
|
347 |
* Returns whether a network interface is up and running. |
|
348 |
* |
|
349 |
* @return <code>true</code> if the interface is up and running. |
|
350 |
* @exception SocketException if an I/O error occurs. |
|
351 |
* @since 1.6 |
|
352 |
*/ |
|
353 |
||
354 |
public boolean isUp() throws SocketException { |
|
355 |
return isUp0(name, index); |
|
356 |
} |
|
357 |
||
358 |
/** |
|
359 |
* Returns whether a network interface is a loopback interface. |
|
360 |
* |
|
361 |
* @return <code>true</code> if the interface is a loopback interface. |
|
362 |
* @exception SocketException if an I/O error occurs. |
|
363 |
* @since 1.6 |
|
364 |
*/ |
|
365 |
||
366 |
public boolean isLoopback() throws SocketException { |
|
367 |
return isLoopback0(name, index); |
|
368 |
} |
|
369 |
||
370 |
/** |
|
371 |
* Returns whether a network interface is a point to point interface. |
|
372 |
* A typical point to point interface would be a PPP connection through |
|
373 |
* a modem. |
|
374 |
* |
|
375 |
* @return <code>true</code> if the interface is a point to point |
|
376 |
* interface. |
|
377 |
* @exception SocketException if an I/O error occurs. |
|
378 |
* @since 1.6 |
|
379 |
*/ |
|
380 |
||
381 |
public boolean isPointToPoint() throws SocketException { |
|
382 |
return isP2P0(name, index); |
|
383 |
} |
|
384 |
||
385 |
/** |
|
386 |
* Returns whether a network interface supports multicasting or not. |
|
387 |
* |
|
388 |
* @return <code>true</code> if the interface supports Multicasting. |
|
389 |
* @exception SocketException if an I/O error occurs. |
|
390 |
* @since 1.6 |
|
391 |
*/ |
|
392 |
||
393 |
public boolean supportsMulticast() throws SocketException { |
|
394 |
return supportsMulticast0(name, index); |
|
395 |
} |
|
396 |
||
397 |
/** |
|
398 |
* Returns the hardware address (usually MAC) of the interface if it |
|
399 |
* has one and if it can be accessed given the current privileges. |
|
400 |
* |
|
401 |
* @return a byte array containing the address or <code>null</code> if |
|
402 |
* the address doesn't exist or is not accessible. |
|
403 |
* @exception SocketException if an I/O error occurs. |
|
404 |
* @since 1.6 |
|
405 |
*/ |
|
406 |
public byte[] getHardwareAddress() throws SocketException { |
|
407 |
for (InetAddress addr : addrs) { |
|
408 |
if (addr instanceof Inet4Address) { |
|
409 |
return getMacAddr0(((Inet4Address)addr).getAddress(), name, index); |
|
410 |
} |
|
411 |
} |
|
412 |
return getMacAddr0(null, name, index); |
|
413 |
} |
|
414 |
||
415 |
/** |
|
416 |
* Returns the Maximum Transmission Unit (MTU) of this interface. |
|
417 |
* |
|
418 |
* @return the value of the MTU for that interface. |
|
419 |
* @exception SocketException if an I/O error occurs. |
|
420 |
* @since 1.6 |
|
421 |
*/ |
|
422 |
public int getMTU() throws SocketException { |
|
423 |
return getMTU0(name, index); |
|
424 |
} |
|
425 |
||
426 |
/** |
|
427 |
* Returns whether this interface is a virtual interface (also called |
|
428 |
* subinterface). |
|
429 |
* Virtual interfaces are, on some systems, interfaces created as a child |
|
430 |
* of a physical interface and given different settings (like address or |
|
431 |
* MTU). Usually the name of the interface will the name of the parent |
|
432 |
* followed by a colon (:) and a number identifying the child since there |
|
433 |
* can be several virtual interfaces attached to a single physical |
|
434 |
* interface. |
|
435 |
* |
|
436 |
* @return <code>true</code> if this interface is a virtual interface. |
|
437 |
* @since 1.6 |
|
438 |
*/ |
|
439 |
public boolean isVirtual() { |
|
440 |
return virtual; |
|
441 |
} |
|
442 |
||
443 |
private native static boolean isUp0(String name, int ind) throws SocketException; |
|
444 |
private native static boolean isLoopback0(String name, int ind) throws SocketException; |
|
445 |
private native static boolean supportsMulticast0(String name, int ind) throws SocketException; |
|
446 |
private native static boolean isP2P0(String name, int ind) throws SocketException; |
|
447 |
private native static byte[] getMacAddr0(byte[] inAddr, String name, int ind) throws SocketException; |
|
448 |
private native static int getMTU0(String name, int ind) throws SocketException; |
|
449 |
||
450 |
/** |
|
451 |
* Compares this object against the specified object. |
|
452 |
* The result is <code>true</code> if and only if the argument is |
|
453 |
* not <code>null</code> and it represents the same NetworkInterface |
|
454 |
* as this object. |
|
455 |
* <p> |
|
456 |
* Two instances of <code>NetworkInterface</code> represent the same |
|
457 |
* NetworkInterface if both name and addrs are the same for both. |
|
458 |
* |
|
459 |
* @param obj the object to compare against. |
|
460 |
* @return <code>true</code> if the objects are the same; |
|
461 |
* <code>false</code> otherwise. |
|
462 |
* @see java.net.InetAddress#getAddress() |
|
463 |
*/ |
|
464 |
public boolean equals(Object obj) { |
|
465 |
if ((obj == null) || !(obj instanceof NetworkInterface)) { |
|
466 |
return false; |
|
467 |
} |
|
468 |
NetworkInterface netIF = (NetworkInterface)obj; |
|
469 |
if (name != null ) { |
|
470 |
if (netIF.getName() != null) { |
|
471 |
if (!name.equals(netIF.getName())) { |
|
472 |
return false; |
|
473 |
} |
|
474 |
} else { |
|
475 |
return false; |
|
476 |
} |
|
477 |
} else { |
|
478 |
if (netIF.getName() != null) { |
|
479 |
return false; |
|
480 |
} |
|
481 |
} |
|
482 |
Enumeration newAddrs = netIF.getInetAddresses(); |
|
483 |
int i = 0; |
|
484 |
for (i = 0; newAddrs.hasMoreElements();newAddrs.nextElement(), i++); |
|
485 |
if (addrs == null) { |
|
486 |
if (i != 0) { |
|
487 |
return false; |
|
488 |
} |
|
489 |
} else { |
|
490 |
/* |
|
491 |
* Compare number of addresses (in the checked subset) |
|
492 |
*/ |
|
493 |
int count = 0; |
|
494 |
Enumeration e = getInetAddresses(); |
|
495 |
for (; e.hasMoreElements(); count++) { |
|
496 |
e.nextElement(); |
|
497 |
} |
|
498 |
if (i != count) { |
|
499 |
return false; |
|
500 |
} |
|
501 |
} |
|
502 |
newAddrs = netIF.getInetAddresses(); |
|
503 |
for (; newAddrs.hasMoreElements();) { |
|
504 |
boolean equal = false; |
|
505 |
Enumeration thisAddrs = getInetAddresses(); |
|
506 |
InetAddress newAddr = (InetAddress)newAddrs.nextElement(); |
|
507 |
for (; thisAddrs.hasMoreElements();) { |
|
508 |
InetAddress thisAddr = (InetAddress)thisAddrs.nextElement(); |
|
509 |
if (thisAddr.equals(newAddr)) { |
|
510 |
equal = true; |
|
511 |
} |
|
512 |
} |
|
513 |
if (!equal) { |
|
514 |
return false; |
|
515 |
} |
|
516 |
} |
|
517 |
return true; |
|
518 |
} |
|
519 |
||
520 |
public int hashCode() { |
|
521 |
int count = 0; |
|
522 |
if (addrs != null) { |
|
523 |
for (int i = 0; i < addrs.length; i++) { |
|
524 |
count += addrs[i].hashCode(); |
|
525 |
} |
|
526 |
} |
|
527 |
return count; |
|
528 |
} |
|
529 |
||
530 |
public String toString() { |
|
531 |
String result = "name:"; |
|
532 |
result += name == null? "null": name; |
|
533 |
if (displayName != null) { |
|
534 |
result += " (" + displayName + ")"; |
|
535 |
} |
|
536 |
result += " index: "+index+" addresses:\n"; |
|
537 |
for (Enumeration e = getInetAddresses(); e.hasMoreElements(); ) { |
|
538 |
InetAddress addr = (InetAddress)e.nextElement(); |
|
539 |
result += addr+";\n"; |
|
540 |
} |
|
541 |
return result; |
|
542 |
} |
|
543 |
private static native void init(); |
|
544 |
||
545 |
} |