]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Common.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Common.c
index 004a8bc7034d0488d5ab5d43e7bfe8796ca1f303..c756a2dbf7e41514dc1cc81018a5304188f07da0 100644 (file)
@@ -1,13 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -267,3 +261,46 @@ Ip4NtohHead (
 \r
   return Head;\r
 }\r
+\r
+\r
+/**\r
+  Validate that Ip/Netmask pair is OK to be used as station\r
+  address. Only continuous netmasks are supported. and check\r
+  that StationAddress is a unicast address on the newtwork.\r
+\r
+  @param[in]  Ip                 The IP address to validate.\r
+  @param[in]  Netmask            The netmaks of the IP.\r
+\r
+  @retval TRUE                   The Ip/Netmask pair is valid.\r
+  @retval FALSE                  The Ip/Netmask pair is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+Ip4StationAddressValid (\r
+  IN IP4_ADDR               Ip,\r
+  IN IP4_ADDR               Netmask\r
+  )\r
+{\r
+  //\r
+  // Only support the station address with 0.0.0.0/0 to enable DHCP client.\r
+  //\r
+  if (Netmask == IP4_ALLZERO_ADDRESS) {\r
+    return (BOOLEAN) (Ip == IP4_ALLZERO_ADDRESS);\r
+  }\r
+\r
+  //\r
+  // Only support the continuous net masks\r
+  //\r
+  if (NetGetMaskLength (Netmask) == (IP4_MASK_MAX + 1)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Station address can't be class D or class E address\r
+  //\r
+  if (NetGetIpClass (Ip) > IP4_ADDR_CLASSC) {\r
+    return FALSE;\r
+  }\r
+\r
+  return NetIp4IsUnicast (Ip, Netmask);\r
+}\r