美文网首页安卓面试
Android日常问题收集

Android日常问题收集

作者: 飞指 | 来源:发表于2020-01-14 15:52 被阅读0次

    如何在IPv4的网络中访问IPv6具体实现方案

      /**
         *
         * @param hostname
         * @return
         * @throws UnknownHostException
         */
        @Override
        public List<InetAddress> lookup(String hostname) throws UnknownHostException {
            if (hostname == null) {
                throw new UnknownHostException("hostname == null");
            } else {
                List<InetAddress> inetAddresses = new ArrayList<>();
                InetAddress[] host = InetAddress.getAllByName(hostname);
                for (InetAddress inetAddress : host
                ) {
                    if (inetAddress instanceof Inet4Address) {
                        inetAddresses.add(0, inetAddress);
                    } else {
                        inetAddresses.add(inetAddress);
                    }
                }
                return inetAddresses;
            }
        }
    

    相关文章

      网友评论

        本文标题:Android日常问题收集

        本文链接:https://www.haomeiwen.com/subject/xqdaactx.html