Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9eae9705 authored by yuanyunli's avatar yuanyunli Committed by Lorenzo Colitti
Browse files

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)
parent 2e67b9bd
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -308,6 +308,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;
    }