01: /*
02: * @(#)Inet6AddressImpl.java 1.5 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package java.net;
27:
28: /*
29: * Package private implementation of InetAddressImpl for dual
30: * IPv4/IPv6 stack.
31: * <p>
32: * If InetAddress.preferIPv6Address is true then anyLocalAddress(),
33: * loopbackAddress(), and localHost() will return IPv6 addresses,
34: * otherwise IPv4 addresses.
35: *
36: * @since 1.4
37: */
38:
39: class Inet6AddressImpl implements InetAddressImpl {
40: public native String getLocalHostName() throws UnknownHostException;
41:
42: public native byte[][] lookupAllHostAddr(String hostname)
43: throws UnknownHostException;
44:
45: public native String getHostByAddr(byte[] addr)
46: throws UnknownHostException;
47:
48: public synchronized InetAddress anyLocalAddress() {
49: if (anyLocalAddress == null) {
50: if (InetAddress.preferIPv6Address) {
51: anyLocalAddress = new Inet6Address();
52: anyLocalAddress.hostName = "::";
53: } else {
54: anyLocalAddress = (new Inet4AddressImpl())
55: .anyLocalAddress();
56: }
57: }
58: return anyLocalAddress;
59: }
60:
61: public synchronized InetAddress loopbackAddress() {
62: if (loopbackAddress == null) {
63: if (InetAddress.preferIPv6Address) {
64: byte[] loopback = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
65: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66: 0x00, 0x01 };
67: loopbackAddress = new Inet6Address("localhost",
68: loopback);
69: } else {
70: loopbackAddress = (new Inet4AddressImpl())
71: .loopbackAddress();
72: }
73: }
74: return loopbackAddress;
75: }
76:
77: private InetAddress anyLocalAddress;
78: private InetAddress loopbackAddress;
79: }
|