zoukankan      html  css  js  c++  java
  • Android : 有线DHCP信息保存到属性值

    修改源码路径:frameworksaseservices etjavaandroid etdhcpDhcpClient.java

    1、定义对应属性变量:

        // Patch Begin - Sheldon
        private static final String PROPERTY_DHCPCLIENT_IP      = "dhcp.eth0.ipaddress";
        private static final String PROPERTY_DHCPCLIENT_MASK    = "dhcp.eth0.mask";
        private static final String PROPERTY_DHCPCLIENT_GATEWAY = "dhcp.eth0.gateway";
        private static final String PROPERTY_DHCPCLIENT_DNS1    = "dhcp.eth0.dns1";
        private static final String PROPERTY_DHCPCLIENT_DNS2    = "dhcp.eth0.dns2";
        // Patch end

    2.从acceptDhcpResults方法的results参数中提取IP地址、子网掩码、网关、DNS等信息。注:子网掩码是通过PrefixLength转换所得。

        private void acceptDhcpResults(DhcpResults results, String msg) {
            mDhcpLease = results;
            mOffer = null;
            Log.d(TAG, msg + " lease: " + mDhcpLease);
    
            // Patch Begin - Sheldon
            if (mIfaceName != null && (mIfaceName.equals("eth0") || mIfaceName.equals("veth0")))
            {
                try {
                        String ipAddr  = results.ipAddress.getAddress().getHostAddress();
                        int preFixLen  = results.ipAddress.getPrefixLength();
    
                        // Convert PrefixLength to subnet mask
                        int value = 0xffffffff << (32 - preFixLen);
                        byte[] bytes = new byte[]{ 
                                (byte)(value >> 24), (byte)(value >> 16 & 0xff), (byte)(value >> 8 & 0xff), (byte)(value & 0xff)};
                        InetAddress netAddr = InetAddress.getByAddress(bytes);
                        String subNetMask  = netAddr.getHostAddress();
    
                        String gateWay = deleteCharString(results.gateway.toString(), '/');
                        String dns1    = deleteCharString(results.dnsServers.get(0).toString(), '/');
                        String dns2    = deleteCharString(results.dnsServers.get(1).toString(), '/');
    
                        SystemProperties.set(PROPERTY_DHCPCLIENT_IP, ipAddr);
                        SystemProperties.set(PROPERTY_DHCPCLIENT_MASK, subNetMask);
                        SystemProperties.set(PROPERTY_DHCPCLIENT_GATEWAY, gateWay);
                        SystemProperties.set(PROPERTY_DHCPCLIENT_DNS1, dns1);
                        SystemProperties.set(PROPERTY_DHCPCLIENT_DNS2, dns2);
               
                } catch (Exception e) {
                        e.printStackTrace();
                }
            }
            //Patch end
    
            notifySuccess();
        }
  • 相关阅读:
    liunx-centos-基础命令详解(1) -主要内容来自 —https://www.cnblogs.com/caozy/p/9261224.html
    阿里云搭建香港代理服务器 shadownsocks
    ssh 操作 esxi 基本命令
    surpace pro 检测维修记录
    新的开始
    Linux就该这么学04学习笔记
    博客园添加旋转的正方体特效
    博客园添加鼠标动态线条
    day01 python初识、数据类型、流程控制
    Hadoop学习(1)-hdfs安装及其一些操作
  • 原文地址:https://www.cnblogs.com/blogs-of-lxl/p/12202939.html
Copyright © 2011-2022 走看看