Skip to content

Commit 61da29a

Browse files
committed
Ensure DHCP requests have nonempty hostnames
If the net.hostname property is empty or not found, Android issues DHCP requests with an empty hostname field (option 12). RFC2132 section 3.14 prescribes a minimum length of 1 byte for the hostname. To fix this, a generic 'android-dhcp' hostname is used as a fallback. Change-Id: I7a92e7295f72b3255e4fba6498fb4039906eb702
1 parent 5587ea4 commit 61da29a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

services/net/java/android/net/dhcp/DhcpPacket.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,12 @@ protected static void addTlvEnd(ByteBuffer buf) {
602602
protected void addCommonClientTlvs(ByteBuffer buf) {
603603
addTlv(buf, DHCP_MAX_MESSAGE_SIZE, (short) MAX_LENGTH);
604604
addTlv(buf, DHCP_VENDOR_CLASS_ID, "android-dhcp-" + Build.VERSION.RELEASE);
605-
addTlv(buf, DHCP_HOST_NAME, SystemProperties.get("net.hostname"));
605+
606+
/* the default 'android-dhcp' is there to make sure the hostname is
607+
* never empty, because the DHCP standard forbids it (RFC2132, section
608+
* 3.14) and certain DHCP forwarders and servers ignore such malformed
609+
* requests */
610+
addTlv(buf, DHCP_HOST_NAME, SystemProperties.get("net.hostname", "android-dhcp"));
606611
}
607612

608613
/**

0 commit comments

Comments
 (0)