1 /* |
1 /* |
2 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package sun.nio.ch; |
26 package sun.nio.ch; |
27 |
27 |
28 import java.io.*; |
28 import java.io.FileDescriptor; |
29 import java.net.*; |
29 import java.io.IOException; |
30 import java.nio.channels.*; |
30 import java.net.Inet4Address; |
31 import java.util.*; |
31 import java.net.Inet6Address; |
|
32 import java.net.InetAddress; |
|
33 import java.net.InetSocketAddress; |
|
34 import java.net.NetworkInterface; |
|
35 import java.net.ProtocolFamily; |
|
36 import java.net.SocketAddress; |
|
37 import java.net.SocketException; |
|
38 import java.net.SocketOption; |
|
39 import java.net.StandardProtocolFamily; |
|
40 import java.net.StandardSocketOptions; |
|
41 import java.net.UnknownHostException; |
|
42 import java.nio.channels.AlreadyBoundException; |
|
43 import java.nio.channels.ClosedChannelException; |
|
44 import java.nio.channels.NotYetBoundException; |
|
45 import java.nio.channels.NotYetConnectedException; |
|
46 import java.nio.channels.UnresolvedAddressException; |
|
47 import java.nio.channels.UnsupportedAddressTypeException; |
32 import java.security.AccessController; |
48 import java.security.AccessController; |
33 import java.security.PrivilegedAction; |
49 import java.security.PrivilegedAction; |
|
50 import java.util.Enumeration; |
|
51 |
34 import sun.net.ext.ExtendedSocketOptions; |
52 import sun.net.ext.ExtendedSocketOptions; |
35 import sun.security.action.GetPropertyAction; |
53 import sun.security.action.GetPropertyAction; |
36 |
54 |
37 public class Net { |
55 public class Net { |
38 |
56 |
111 if (isa.isUnresolved()) |
129 if (isa.isUnresolved()) |
112 throw new UnresolvedAddressException(); // ## needs arg |
130 throw new UnresolvedAddressException(); // ## needs arg |
113 InetAddress addr = isa.getAddress(); |
131 InetAddress addr = isa.getAddress(); |
114 if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) |
132 if (!(addr instanceof Inet4Address || addr instanceof Inet6Address)) |
115 throw new IllegalArgumentException("Invalid address type"); |
133 throw new IllegalArgumentException("Invalid address type"); |
|
134 return isa; |
|
135 } |
|
136 |
|
137 static InetSocketAddress checkAddress(SocketAddress sa, ProtocolFamily family) { |
|
138 InetSocketAddress isa = checkAddress(sa); |
|
139 if (family == StandardProtocolFamily.INET) { |
|
140 InetAddress addr = isa.getAddress(); |
|
141 if (!(addr instanceof Inet4Address)) |
|
142 throw new UnsupportedAddressTypeException(); |
|
143 } |
116 return isa; |
144 return isa; |
117 } |
145 } |
118 |
146 |
119 static InetSocketAddress asInetSocketAddress(SocketAddress sa) { |
147 static InetSocketAddress asInetSocketAddress(SocketAddress sa) { |
120 if (!(sa instanceof InetSocketAddress)) |
148 if (!(sa instanceof InetSocketAddress)) |