其他分享
首页 > 其他分享> > Android7.1 关闭路由器DHCP后还能获取到ip地址

Android7.1 关闭路由器DHCP后还能获取到ip地址

作者:互联网

frameworks\base\services\net\java\android\net\dhcp\DhcpClient.java   确定 mIsIpRecoverEnabled=false;解决此问题。 原因:    private boolean doIpRecover() {         if (mIsIpRecoverEnabled == false) {             Log.d(TAG, "IP recover: it was disabled");             return false;         }         if (mPastDhcpLease == null) {             Log.d(TAG, "IP recover: mPastDhcpLease is empty");             return false;         }         Log.d(TAG, "IP recover: mPastDhcpLease = " + mPastDhcpLease);

 

        long reCaculatedLeaseMillis =             mPastDhcpLease.systemExpiredTime - SystemClock.elapsedRealtime();         Log.d(TAG, "IP recover: reCaculatedLeaseMillis = " + reCaculatedLeaseMillis);

 

        if (reCaculatedLeaseMillis < 0) {             // configure infinite lease             mDhcpLeaseExpiry = 0;             Log.e(TAG, "IP recover: lease had been expired! configure to infinite lease");         } else {             mDhcpLeaseExpiry = SystemClock.elapsedRealtime() + reCaculatedLeaseMillis;             Log.d(TAG, "IP recover: mDhcpLeaseExpiry = " + mDhcpLeaseExpiry);         }

 

        byte arpResult[] = null;         ArpPeer ap = null;         boolean retVal = false;         try {             InetAddress ipAddress = mPastDhcpLease.ipAddress.getAddress();             Log.d(TAG, "IP recover: arp address = " +                 "#$%K" +                 logDumpIpv4(3, ipAddress.getHostAddress()));             ap = new ArpPeer(mIfaceName, Inet4Address.ANY, ipAddress);             // doArp will blocking several seconds, to create thread if needed             arpResult = ap.doArp(5000);             if (arpResult == null) {                 int leaseDuration = (int)reCaculatedLeaseMillis/1000;                 mPastDhcpLease.setLeaseDuration(leaseDuration);                 acceptDhcpResults(mPastDhcpLease, "Confirmed");                 Log.d(TAG, "doIpRecover no arp response, IP can be reused");                 retVal = true;             } else {                 Log.d(TAG, "doIpRecover DAD detected!!");             }         } catch (ErrnoException ee) {             Log.d(TAG, "err :" + ee);         } catch (IllegalArgumentException ie) {             Log.d(TAG, "err :" + ie);         } catch (SocketException se) {             Log.d(TAG, "err :" + se);         } finally {             if (ap != null)    ap.close();         }         return retVal;     }     /// @}

标签:mPastDhcpLease,Log,ip,reCaculatedLeaseMillis,Android7.1,TAG,IP,DHCP,recover
来源: https://www.cnblogs.com/gwj0424/p/15689854.html