/* ASSERT if Ip1 or Ip2 is NULL. ASSERT if PrefixLength exceeds or equals to IP6_PREFIX_MAX. */
BOOLEAN EFIAPI NetIp6IsNetEqual(EFI_IPv6_ADDRESS *Ip1, EFI_IPv6_ADDRESS *Ip2, UINT8 PrefixLength)
/* ASSERT if Ip1 or Ip2 is NULL. ASSERT if PrefixLength exceeds or equals to IP6_PREFIX_MAX. */
BOOLEAN EFIAPI NetIp6IsNetEqual(EFI_IPv6_ADDRESS *Ip1, EFI_IPv6_ADDRESS *Ip2, UINT8 PrefixLength)
{
  UINT8  Byte;
  UINT8  Bit;
  UINT8  Mask;
  ASSERT ((Ip1 != NULL) && (Ip2 != NULL) && (PrefixLength < IP6_PREFIX_MAX));
  if (PrefixLength == 0) {
    return TRUE;
  }
  Byte = (UINT8)(PrefixLength / 8);
  Bit  = (UINT8)(PrefixLength % 8);
  if (CompareMem (Ip1, Ip2, Byte) != 0) {
    return FALSE;
  }
  if (Bit > 0) {
    Mask = (UINT8)(0xFF << (8 - Bit));
    ASSERT (Byte < 16);
    if (Byte >= 16) {
      return FALSE;
    }
    if ((Ip1->Addr[Byte] & Mask) != (Ip2->Addr[Byte] & Mask)) {
      return FALSE;
    }
  }
  return TRUE;
}