FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b59)
Java HotSpot(TM) Client VM (build 16.0-b03, mixed mode, sharing)
&
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
System:
Microsoft Windows XP
Professional
Version 2002
Service Pack 3
A DESCRIPTION OF THE PROBLEM :
Using IPv6 addresses in conjuction with NIO channels raises a "java.net.SocketException: Address family not supported by protocol
family".
Doing the same operation directly on a socket instance (i.e. without getting the socket from a channel) works.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply execute the piece of code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
==> 1
==> 2
==> 3
ACTUAL -
==> 1
==> 2
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.net.SocketException: Address family not supported by protocol family: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:321)
at sun.nio.ch.Net.bind(Net.java:313)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:
196)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
at ipv6.main(ipv6.java:28)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.ServerSocketChannel;
class ipv6 {
static public void main(String[] notUsed) {
try {
byte[] addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1};
InetAddress inetAddr = InetAddress.getByAddress(addr);
InetSocketAddress addr_8501 = new
InetSocketAddress(inetAddr, 8501);
InetSocketAddress addr_8502 = new
InetSocketAddress(inetAddr, 8502);
System.out.println("==> 1");
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(addr_8501); // This works
System.out.println("==> 2");
ServerSocketChannel channel = ServerSocketChannel.open();
channel.socket().bind(addr_8502); //This does not work
System.out.println("==> 3");
} catch (Throwable t) {
t.printStackTrace();
}
}
}
---------- END SOURCE ----------
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b59)
Java HotSpot(TM) Client VM (build 16.0-b03, mixed mode, sharing)
&
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
System:
Microsoft Windows XP
Professional
Version 2002
Service Pack 3
A DESCRIPTION OF THE PROBLEM :
Using IPv6 addresses in conjuction with NIO channels raises a "java.net.SocketException: Address family not supported by protocol
family".
Doing the same operation directly on a socket instance (i.e. without getting the socket from a channel) works.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply execute the piece of code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
==> 1
==> 2
==> 3
ACTUAL -
==> 1
==> 2
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.net.SocketException: Address family not supported by protocol family: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:321)
at sun.nio.ch.Net.bind(Net.java:313)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:
196)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
at ipv6.main(ipv6.java:28)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.ServerSocketChannel;
class ipv6 {
static public void main(String[] notUsed) {
try {
byte[] addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1};
InetAddress inetAddr = InetAddress.getByAddress(addr);
InetSocketAddress addr_8501 = new
InetSocketAddress(inetAddr, 8501);
InetSocketAddress addr_8502 = new
InetSocketAddress(inetAddr, 8502);
System.out.println("==> 1");
ServerSocket serverSocket = new ServerSocket();
serverSocket.bind(addr_8501); // This works
System.out.println("==> 2");
ServerSocketChannel channel = ServerSocketChannel.open();
channel.socket().bind(addr_8502); //This does not work
System.out.println("==> 3");
} catch (Throwable t) {
t.printStackTrace();
}
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-4640544 New I/O: Complete socket-channel functionality
-
- Closed
-
- relates to
-
JDK-6230761 (so) NIO channels with IPv6 on Windows
-
- Resolved
-