use of java.net.InetAddress in project guava by google.
the class InetAddressesTest method testForStringIPv6EightColons.
public void testForStringIPv6EightColons() throws UnknownHostException {
String[] eightColons = { "::7:6:5:4:3:2:1", "::7:6:5:4:3:2:0", "7:6:5:4:3:2:1::", "0:6:5:4:3:2:1::" };
for (int i = 0; i < eightColons.length; i++) {
InetAddress ipv6Addr = null;
// Shouldn't hit DNS, because it's an IP string literal.
ipv6Addr = InetAddress.getByName(eightColons[i]);
assertEquals(ipv6Addr, InetAddresses.forString(eightColons[i]));
assertTrue(InetAddresses.isInetAddress(eightColons[i]));
}
}
use of java.net.InetAddress in project j2objc by google.
the class DatagramChannelTest method test_bind_IPv6.
public void test_bind_IPv6() throws Exception {
InetAddress bindAddress = getNonLoopbackNetworkInterfaceAddress(false);
test_bind(bindAddress);
}
use of java.net.InetAddress in project j2objc by google.
the class TestSSLContext method clientAuth.
/**
* Returns an SSLSocketFactory that calls setWantClientAuth and
* setNeedClientAuth as specified on all returned sockets.
*/
public static SSLSocketFactory clientAuth(final SSLSocketFactory sf, final boolean want, final boolean need) {
return new SSLSocketFactory() {
private SSLSocket set(Socket socket) {
SSLSocket s = (SSLSocket) socket;
s.setWantClientAuth(want);
s.setNeedClientAuth(need);
return s;
}
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
return set(sf.createSocket(host, port));
}
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
return set(sf.createSocket(host, port, localHost, localPort));
}
public Socket createSocket(InetAddress host, int port) throws IOException {
return set(sf.createSocket(host, port));
}
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
return set(sf.createSocket(address, port));
}
public String[] getDefaultCipherSuites() {
return sf.getDefaultCipherSuites();
}
public String[] getSupportedCipherSuites() {
return sf.getSupportedCipherSuites();
}
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
return set(sf.createSocket(s, host, port, autoClose));
}
};
}
use of java.net.InetAddress in project j2objc by google.
the class TestSSLContext method create.
/**
* TestSSLContext creation method that allows separate creation of client and server key store
*/
public static TestSSLContext create(KeyStore clientKeyStore, char[] clientStorePassword, KeyStore serverKeyStore, char[] serverStorePassword, KeyManager[] clientKeyManagers, KeyManager[] serverKeyManagers, TrustManager clientTrustManagers, TrustManager serverTrustManagers, SSLContext clientContext, SSLContext serverContext) {
try {
SSLServerSocket serverSocket = (SSLServerSocket) serverContext.getServerSocketFactory().createServerSocket(0);
InetAddress host = InetAddress.getLocalHost();
int port = serverSocket.getLocalPort();
return new TestSSLContext(clientKeyStore, clientStorePassword, serverKeyStore, serverStorePassword, clientKeyManagers, serverKeyManagers, clientContext, serverContext, serverSocket, host, port);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of java.net.InetAddress in project j2objc by google.
the class SocketTest method checkSocketLocalAndRemoteAddresses.
// http://code.google.com/p/android/issues/detail?id=3123
// http://code.google.com/p/android/issues/detail?id=1933
/* Fails on machines with IPv6 connections, both on JRE and j2objc.
public void test_socketLocalAndRemoteAddresses() throws Exception {
checkSocketLocalAndRemoteAddresses(false);
checkSocketLocalAndRemoteAddresses(true);
}
*/
public void checkSocketLocalAndRemoteAddresses(boolean setOptions) throws Exception {
InetAddress host = InetAddress.getLocalHost();
// Open a local server port.
ServerSocketChannel ssc = ServerSocketChannel.open();
InetSocketAddress listenAddr = new InetSocketAddress(host, 0);
ssc.bind(listenAddr, 0);
ServerSocket ss = ssc.socket();
// Open a socket to the local port.
SocketChannel out = SocketChannel.open();
out.configureBlocking(false);
if (setOptions) {
out.socket().setTcpNoDelay(false);
}
InetSocketAddress addr = new InetSocketAddress(host, ssc.socket().getLocalPort());
out.connect(addr);
while (!out.finishConnect()) {
Thread.sleep(1);
}
SocketChannel in = ssc.accept();
if (setOptions) {
in.socket().setTcpNoDelay(false);
}
InetSocketAddress listenAddress = (InetSocketAddress) in.getLocalAddress();
InetSocketAddress outRemoteAddress = (InetSocketAddress) out.socket().getRemoteSocketAddress();
InetSocketAddress outLocalAddress = (InetSocketAddress) out.socket().getLocalSocketAddress();
InetSocketAddress inLocalAddress = (InetSocketAddress) in.socket().getLocalSocketAddress();
InetSocketAddress inRemoteAddress = (InetSocketAddress) in.socket().getRemoteSocketAddress();
// System.err.println("listenAddress: " + listenAddr);
// System.err.println("inLocalAddress: " + inLocalAddress);
// System.err.println("inRemoteAddress: " + inRemoteAddress);
// System.err.println("outLocalAddress: " + outLocalAddress);
// System.err.println("outRemoteAddress: " + outRemoteAddress);
assertFalse(ssc.socket().isClosed());
assertTrue(ssc.socket().isBound());
assertTrue(in.isConnected());
assertTrue(in.socket().isConnected());
assertTrue(out.socket().isConnected());
assertTrue(out.isConnected());
in.close();
out.close();
ssc.close();
assertTrue(ssc.socket().isClosed());
assertTrue(ssc.socket().isBound());
assertFalse(in.isConnected());
assertFalse(in.socket().isConnected());
assertFalse(out.socket().isConnected());
assertFalse(out.isConnected());
assertNull(in.socket().getRemoteSocketAddress());
assertNull(out.socket().getRemoteSocketAddress());
// As per docs and RI - server socket local address methods continue to return the bind()
// addresses even after close().
assertEquals(listenAddress, ssc.socket().getLocalSocketAddress());
// As per docs and RI - socket local address methods return the wildcard address before
// bind() and after close(), but the port will be the same as it was before close().
InetSocketAddress inLocalAddressAfterClose = (InetSocketAddress) in.socket().getLocalSocketAddress();
assertTrue(inLocalAddressAfterClose.getAddress().isAnyLocalAddress());
assertEquals(inLocalAddress.getPort(), inLocalAddressAfterClose.getPort());
InetSocketAddress outLocalAddressAfterClose = (InetSocketAddress) out.socket().getLocalSocketAddress();
assertTrue(outLocalAddressAfterClose.getAddress().isAnyLocalAddress());
assertEquals(outLocalAddress.getPort(), outLocalAddressAfterClose.getPort());
}
Aggregations