java.net.Inet6Address#isLinkLocalAddress ( )源码实例Demo

下面列出了java.net.Inet6Address#isLinkLocalAddress ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: NetworkBridge.java
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);
    }
}
 
@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);
            }
        }
    }
}
 
源代码3 项目: RipplePower   文件: IP46Utils.java
static boolean isLLunicast(Inet6Address a) {
	return a.isLinkLocalAddress();
}