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

The following examples show how to use java.net.Inet6Address#getHostAddress() . These examples are extracted from open source projects. 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
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
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
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
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
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
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
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
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
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
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
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 12
Source Project: flink   File: IPv6HostnamesITCase.java    License: 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
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 Project: flink   File: IPv6HostnamesITCase.java    License: 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 15
Source Project: ovsdb   File: SouthboundUtils.java    License: 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 16
/**
 * 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 17
public static IpAddress createIpAddress(Inet6Address address) {
    Ipv6Address ipv6 = new Ipv6Address(address.getHostAddress());
    return new IpAddress(ipv6);
}
 
Example 18
Source Project: datax-web   File: IpUtil.java    License: 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;
}
 
Example 19
Source Project: xxl-rpc   File: IpUtil.java    License: 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 Project: xxl-job   File: IpUtil.java    License: 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;
}