Java Code Examples for java.net.Inet6Address#getHostAddress()

The following examples show how to use java.net.Inet6Address#getHostAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Inet6AddressSerializationTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 2
Source File: Inet6AddressSerializationTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 3
Source File: Inet6AddressSerializationTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 4
Source File: Inet6AddressSerializationTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 5
Source File: Inet6AddressSerializationTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 6
Source File: Inet6AddressSerializationTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 7
Source File: Inet6AddressSerializationTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 8
Source File: Inet6AddressSerializationTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 9
Source File: Inet6AddressSerializationTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 10
Source File: Inet6AddressSerializationTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void displayExpectedInet6Address(Inet6Address expectedInet6Address) {

        String expectedHostName = expectedInet6Address.getHostName();
        byte[] expectedAddress = expectedInet6Address.getAddress();
        String expectedHostAddress = expectedInet6Address.getHostAddress();
        int expectedScopeId = expectedInet6Address.getScopeId();
        NetworkInterface expectedNetIf = expectedInet6Address
                .getScopedInterface();

        System.err.println("Excpected HostName: " + expectedHostName);
        System.err.println("Expected Address: "
                + Arrays.toString(expectedAddress));
        System.err.println("Expected HostAddress: " + expectedHostAddress);
        System.err.println("Expected Scope Id " + expectedScopeId);
        System.err.println("Expected NetworkInterface " + expectedNetIf);
        System.err.println("Expected Inet6Address " + expectedInet6Address);
    }
 
Example 11
Source File: IPv6HostnamesITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private Configuration getConfiguration() {
	final Inet6Address ipv6address = getLocalIPv6Address();
	if (ipv6address == null) {
		throw new AssumptionViolatedException("--- Cannot find a non-loopback local IPv6 address that Akka/Netty can bind to; skipping IPv6HostnamesITCase");
	}
	final String addressString = ipv6address.getHostAddress();
	log.info("Test will use IPv6 address " + addressString + " for connection tests");

	Configuration config = new Configuration();
	config.setString(JobManagerOptions.ADDRESS, addressString);
	config.setString(TaskManagerOptions.HOST, addressString);
	config.set(TaskManagerOptions.MANAGED_MEMORY_SIZE, MemorySize.parse("16m"));
	return config;
}
 
Example 12
Source File: IPv6HostnamesITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private Configuration getConfiguration() {
	final Inet6Address ipv6address = getLocalIPv6Address();
	if (ipv6address == null) {
		throw new AssumptionViolatedException("--- Cannot find a non-loopback local IPv6 address that Akka/Netty can bind to; skipping IPv6HostnamesITCase");
	}
	final String addressString = ipv6address.getHostAddress();
	log.info("Test will use IPv6 address " + addressString + " for connection tests");

	Configuration config = new Configuration();
	config.setString(JobManagerOptions.ADDRESS, addressString);
	config.setString(TaskManagerOptions.HOST, addressString);
	config.setString(TaskManagerOptions.MANAGED_MEMORY_SIZE, "16m");
	return config;
}
 
Example 13
Source File: DubboLocalIpDetector.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
private static InetAddress normalizeV6Address(Inet6Address address) {
    String addr = address.getHostAddress();
    int i = addr.lastIndexOf('%');
    if (i > 0) {
        try {
            return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
    return address;
}
 
Example 14
Source File: IPv6HostnamesITCase.java    From flink with Apache License 2.0 5 votes vote down vote up
private Configuration getConfiguration() {
	final Inet6Address ipv6address = getLocalIPv6Address();
	if (ipv6address == null) {
		throw new AssumptionViolatedException("--- Cannot find a non-loopback local IPv6 address that Akka/Netty can bind to; skipping IPv6HostnamesITCase");
	}
	final String addressString = ipv6address.getHostAddress();
	log.info("Test will use IPv6 address " + addressString + " for connection tests");

	Configuration config = new Configuration();
	config.setString(JobManagerOptions.ADDRESS, addressString);
	config.setString(TaskManagerOptions.HOST, addressString);
	config.setString(TaskManagerOptions.MANAGED_MEMORY_SIZE, "16m");
	return config;
}
 
Example 15
Source File: TestInetAddressServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
/**
 * Test the properties of an instance of IPV6 InetAddress. Much of the code in this method
 * is the same as the code in the method testNameAndAddress4() but it will test different
 * code paths through our byte-code-rewriting since this method uses an instance of
 * Inet6Address.
 * @param hostName The expected host name
 * @param addressString The expected address string
 * @param addressBytes The expected address bytes
 * @param scopeID the expected scopeID
 * @param inet6Addr The instance of Inet6Address being tested
 * @param response HttpServletResponse used to return failure message
 * @throws IOException If method being tested throws this.
 * @throws AssertionFailedException If an assertion fails
 */
private static void testNameAndAddress6(
    String hostName,
    String addressString,
    byte[] addressBytes,
    int scopeID,
    Inet6Address inet6Addr,
    HttpServletResponse response)
    throws IOException, AssertionFailedException {

  assertNotNull("inet6Addr", inet6Addr, response);

  //getAddress
  byte[] bytes = inet6Addr.getAddress();
  assertNotNull("inet6Addr bytes", bytes, response);
  assertEquals("inet6Addr bytes.length", 16, bytes.length, response);
  for (int i = 0; i < 16; i++) {
    assertEquals("inet6Addr address byte " + i, addressBytes[i], bytes[i], response);
  }

  //getCanonicalHostName should return addressString because user code
  //doesn't have permission to get an actual host name
  String canonicalName = inet6Addr.getCanonicalHostName();
  assertEquals("getCanonicalHostName", addressString, canonicalName.toUpperCase(), response);

  //getHostAddress
  String address = inet6Addr.getHostAddress();
  assertEquals("getHostAddress", addressString, address.toUpperCase(), response);

  //getHostName.
  String name2 = inet6Addr.getHostName().toUpperCase();
  String expectedName = (hostName == null ? addressString : hostName.toUpperCase());
  assertEquals("getHostName", expectedName, name2, response);

  //Misc Properties
  assertFalse("isAnyLocalAddress", inet6Addr.isAnyLocalAddress(), response);
  assertFalse("isLinkLocalAddress", inet6Addr.isLinkLocalAddress(), response);
  assertFalse("isLoopbackAddress", inet6Addr.isLoopbackAddress(), response);
  assertFalse("isMCGlobal", inet6Addr.isMCGlobal(), response);
  assertFalse("isMCLinkLoca", inet6Addr.isMCLinkLocal(), response);
  assertFalse("isMCNodeLocal", inet6Addr.isMCNodeLocal(), response);
  assertFalse("isMCOrgLocal", inet6Addr.isMCOrgLocal(), response);
  assertFalse("isMCSiteLoca", inet6Addr.isMCSiteLocal(), response);
  assertFalse("isMulticastAddress", inet6Addr.isMulticastAddress(), response);
  assertFalse("isSiteLocalAddress", inet6Addr.isSiteLocalAddress(), response);

  //toString
  String s = inet6Addr.toString();
  String prefix = (hostName == null ? addressString : hostName);
  assertEquals(
      "toString", (prefix + "/" + addressString).toUpperCase(), s.toUpperCase(), response);

  //isReachable
  assertFalse("isReachable", inet6Addr.isReachable(1000), response);

  //getScopedInterface
  assertNull("getScopedInterface()", inet6Addr.getScopedInterface(), response);

  //getScopedID
  assertEquals("getScopedID()", scopeID, inet6Addr.getScopeId(), response);

  //getHashCode
  assertFalse("hashCode is 0", 0 == inet6Addr.hashCode(), response);

  //isIPv4Compatible
  assertFalse("is Ipv4Compatible()", inet6Addr.isIPv4CompatibleAddress(), response);
}
 
Example 16
Source File: HwvtepSouthboundMapper.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
public static IpAddress createIpAddress(Inet6Address address) {
    Ipv6Address ipv6 = new Ipv6Address(address.getHostAddress());
    return new IpAddress(ipv6);
}
 
Example 17
Source File: SouthboundUtils.java    From ovsdb with Eclipse Public License 1.0 4 votes vote down vote up
public static IpAddress createIpAddress(Inet6Address address) {
    Ipv6Address ipv6 = new Ipv6Address(address.getHostAddress());
    return new IpAddress(ipv6);
}
 
Example 18
Source File: IpUtil.java    From xxl-rpc with GNU General Public License v3.0 3 votes vote down vote up
/**
 * normalize the ipv6 Address, convert scope name to scope id.
 * e.g.
 * convert
 * fe80:0:0:0:894:aeec:f37d:23e1%en0
 * to
 * fe80:0:0:0:894:aeec:f37d:23e1%5
 * <p>
 * The %5 after ipv6 address is called scope id.
 * see java doc of {@link Inet6Address} for more details.
 *
 * @param address the input address
 * @return the normalized address, with scope id converted to int
 */
private static InetAddress normalizeV6Address(Inet6Address address) {
    String addr = address.getHostAddress();
    int i = addr.lastIndexOf('%');
    if (i > 0) {
        try {
            return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId());
        } catch (UnknownHostException e) {
            // ignore
            logger.debug("Unknown IPV6 address: ", e);
        }
    }
    return address;
}
 
Example 19
Source File: IpUtil.java    From xxl-job with GNU General Public License v3.0 3 votes vote down vote up
/**
 * normalize the ipv6 Address, convert scope name to scope id.
 * e.g.
 * convert
 * fe80:0:0:0:894:aeec:f37d:23e1%en0
 * to
 * fe80:0:0:0:894:aeec:f37d:23e1%5
 * <p>
 * The %5 after ipv6 address is called scope id.
 * see java doc of {@link Inet6Address} for more details.
 *
 * @param address the input address
 * @return the normalized address, with scope id converted to int
 */
private static InetAddress normalizeV6Address(Inet6Address address) {
    String addr = address.getHostAddress();
    int i = addr.lastIndexOf('%');
    if (i > 0) {
        try {
            return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId());
        } catch (UnknownHostException e) {
            // ignore
            logger.debug("Unknown IPV6 address: ", e);
        }
    }
    return address;
}
 
Example 20
Source File: IpUtil.java    From datax-web with MIT License 3 votes vote down vote up
/**
 * normalize the ipv6 Address, convert scope name to scope id.
 * e.g.
 * convert
 * fe80:0:0:0:894:aeec:f37d:23e1%en0
 * to
 * fe80:0:0:0:894:aeec:f37d:23e1%5
 * <p>
 * The %5 after ipv6 address is called scope id.
 * see java doc of {@link Inet6Address} for more details.
 *
 * @param address the input address
 * @return the normalized address, with scope id converted to int
 */
private static InetAddress normalizeV6Address(Inet6Address address) {
    String addr = address.getHostAddress();
    int i = addr.lastIndexOf('%');
    if (i > 0) {
        try {
            return InetAddress.getByName(addr.substring(0, i) + '%' + address.getScopeId());
        } catch (UnknownHostException e) {
            // ignore
            logger.debug("Unknown IPV6 address: ", e);
        }
    }
    return address;
}