Add DhcpServingParams

Those parameters will be used to start DhcpServer or update its
configuration.

Test: runtest DhcpServingParamsTest.java
Bug: b/109584964
Change-Id: Id8d3dcf62d66dcb02accffa8d8500e30f07af452
diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java
index 451435c..34e9476 100644
--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -161,7 +161,7 @@
      * @param hostAddress an int coding for an IPv4 address, where higher-order int byte is
      *                    lower-order IPv4 address byte
      */
-    public static InetAddress intToInet4AddressHTL(int hostAddress) {
+    public static Inet4Address intToInet4AddressHTL(int hostAddress) {
         return intToInet4AddressHTH(Integer.reverseBytes(hostAddress));
     }
 
@@ -169,14 +169,14 @@
      * Convert a IPv4 address from an integer to an InetAddress (0x01020304 -> 1.2.3.4)
      * @param hostAddress an int coding for an IPv4 address
      */
-    public static InetAddress intToInet4AddressHTH(int hostAddress) {
+    public static Inet4Address intToInet4AddressHTH(int hostAddress) {
         byte[] addressBytes = { (byte) (0xff & (hostAddress >> 24)),
                 (byte) (0xff & (hostAddress >> 16)),
                 (byte) (0xff & (hostAddress >> 8)),
                 (byte) (0xff & hostAddress) };
 
         try {
-            return InetAddress.getByAddress(addressBytes);
+            return (Inet4Address) InetAddress.getByAddress(addressBytes);
         } catch (UnknownHostException e) {
             throw new AssertionError();
         }
@@ -409,6 +409,28 @@
     }
 
     /**
+     * Get a prefix mask as Inet4Address for a given prefix length.
+     *
+     * <p>For example 20 -> 255.255.240.0
+     */
+    public static Inet4Address getPrefixMaskAsInet4Address(int prefixLength)
+            throws IllegalArgumentException {
+        return intToInet4AddressHTH(prefixLengthToV4NetmaskIntHTH(prefixLength));
+    }
+
+    /**
+     * Get the broadcast address for a given prefix.
+     *
+     * <p>For example 192.168.0.1/24 -> 192.168.0.255
+     */
+    public static Inet4Address getBroadcastAddress(Inet4Address addr, int prefixLength)
+            throws IllegalArgumentException {
+        final int intBroadcastAddr = inet4AddressToIntHTH(addr)
+                | ~prefixLengthToV4NetmaskIntHTH(prefixLength);
+        return intToInet4AddressHTH(intBroadcastAddr);
+    }
+
+    /**
      * Check if IP address type is consistent between two InetAddress.
      * @return true if both are the same type.  False otherwise.
      */