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

The following examples show how to use java.net.Inet6Address#isLinkLocalAddress() . 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: NetworkBridge.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public static void bind(FileDescriptor fd, InetAddress address, int port) throws SocketException {
    if (address instanceof Inet6Address) {
        Inet6Address inet6Address = (Inet6Address) address;
        if (inet6Address.getScopeId() == 0 && inet6Address.isLinkLocalAddress()) {
            // Linux won't let you bind a link-local address without a scope id.
            // Find one.
            NetworkInterface nif = NetworkInterface.getByInetAddress(address);
            if (nif == null) {
                throw new SocketException("Can't bind to a link-local address without a scope id: " + address);
            }
            try {
                address = Inet6Address.getByAddress(address.getHostName(), address.getAddress(), nif.getIndex());
            } catch (UnknownHostException ex) {
                throw new AssertionError(ex); // Can't happen.
            }
        }
    }
    try {
        NetworkOs.bind(fd, address, port);
    } catch (ErrnoException errnoException) {
        throw new BindException(errnoException.getMessage(), errnoException);
    }
}
 
Example 2
Source File: IPv6ScopeIdMatchUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testNonLoopback() throws Exception {

    for (Map.Entry<NetworkInterface, Set<Inet6Address>> entry : addresses.entrySet()) {
        NetworkInterface nif = entry.getKey();
        for (Inet6Address address : entry.getValue()) {
            String hostAddress = address.getHostAddress();
            int pos = hostAddress.indexOf('%');
            if (pos > -1) {
                hostAddress = hostAddress.substring(0, pos);
            }

            matchCriteriaTest(hostAddress, nif, address, true);
            if (!nif.isVirtual() && (address.isLinkLocalAddress() || address.isSiteLocalAddress())) {
                matchCriteriaTest(hostAddress + "%" + nif.getName(), nif, address, true);
                matchCriteriaTest(hostAddress + "%" + address.getScopeId(), nif, address, true);
                matchCriteriaTest(hostAddress + "%" + (address.getScopeId() + 1), nif, address, false);
                matchCriteriaTest(hostAddress + "%bogus", nif, address, false);
            }
        }
    }
}
 
Example 3
Source File: IP46Utils.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
static boolean isLLunicast(Inet6Address a) {
	return a.isLinkLocalAddress();
}