summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryuanyunli <yuanyunli@vivo.corp-partner.google.com>2019-01-09 16:59:37 +0800
committerLorenzo Colitti <lorenzo@google.com>2019-04-29 10:54:28 +0900
commit9eae9705624670edafdd2181dc46f19e70e8eca4 (patch)
treeef27860a9f68ed535fe7084c014e5454d9452a1f
parent2e67b9bdc73d095997a3d68de0755591df1c7d5e (diff)
Parse the server host name field of the dhcp package
Some hotspot devices will fill in the server host name field of the DHCP package, such as iphone. Parsing the server host name of the DHCP package can help identify ios hotspots. Bug: 120584519 Test: 127423755 Test: builds, boots, wifi works Change-Id: I8c5a7dc8ab117f062f9401f58832edada321436b Merged-In: I60071bc029d25485bf204cfd3a8cebd538ca12b6 (cherry picked from commit 43f1bc9d5399e1d659bb5e7ac08dc31d36345d5f)
-rw-r--r--src/android/net/dhcp/DhcpPacket.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/android/net/dhcp/DhcpPacket.java b/src/android/net/dhcp/DhcpPacket.java
index d7ff98b..c5b75f8 100644
--- a/src/android/net/dhcp/DhcpPacket.java
+++ b/src/android/net/dhcp/DhcpPacket.java
@@ -309,6 +309,11 @@ public abstract class DhcpPacket {
protected final byte[] mClientMac;
/**
+ * The server host name from server.
+ */
+ protected String mServerHostName;
+
+ /**
* Asks the packet object to create a ByteBuffer serialization of
* the packet for transmission.
*/
@@ -848,6 +853,7 @@ public abstract class DhcpPacket {
Inet4Address ipDst = null;
Inet4Address bcAddr = null;
Inet4Address requestedIp = null;
+ String serverHostName = null;
// The following are all unsigned integers. Internally we store them as signed integers of
// the same length because that way we're guaranteed that they can't be out of the range of
@@ -989,9 +995,9 @@ public abstract class DhcpPacket {
packet.get(clientMac);
// skip over address padding (16 octets allocated)
- packet.position(packet.position() + (16 - addrLen)
- + 64 // skip server host name (64 chars)
- + 128); // skip boot file name (128 chars)
+ packet.position(packet.position() + (16 - addrLen));
+ serverHostName = readAsciiString(packet, 64, false);
+ packet.position(packet.position() + 128);
// Ensure this is a DHCP packet with a magic cookie, and not BOOTP. http://b/31850211
if (packet.remaining() < 4) {
@@ -1192,6 +1198,7 @@ public abstract class DhcpPacket {
newPacket.mT2 = T2;
newPacket.mVendorId = vendorId;
newPacket.mVendorInfo = vendorInfo;
+ newPacket.mServerHostName = serverHostName;
return newPacket;
}
@@ -1251,6 +1258,7 @@ public abstract class DhcpPacket {
results.vendorInfo = mVendorInfo;
results.leaseDuration = (mLeaseTime != null) ? mLeaseTime : INFINITE_LEASE;
results.mtu = (mMtu != null && MIN_MTU <= mMtu && mMtu <= MAX_MTU) ? mMtu : 0;
+ results.serverHostName = mServerHostName;
return results;
}