/* This function close the previously opened IP protocol and destroy the IP child. */
EFI_STATUS IpIoCloseProtocolDestroyIpChild(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ChildHandle, IN UINT8 IpVersion)
/* This function close the previously opened IP protocol and destroy the IP child. */
EFI_STATUS IpIoCloseProtocolDestroyIpChild(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ChildHandle, IN UINT8 IpVersion)
{
  EFI_STATUS  Status;
  EFI_GUID    *ServiceBindingGuid;
  EFI_GUID    *IpProtocolGuid;
  if (IpVersion == IP_VERSION_4) {
    ServiceBindingGuid = &gEfiIp4ServiceBindingProtocolGuid;
    IpProtocolGuid     = &gEfiIp4ProtocolGuid;
  } else if (IpVersion == IP_VERSION_6) {
    ServiceBindingGuid = &gEfiIp6ServiceBindingProtocolGuid;
    IpProtocolGuid     = &gEfiIp6ProtocolGuid;
  } else {
    return EFI_UNSUPPORTED;
  }
  Status = gBS->CloseProtocol (
                  ChildHandle,
                  IpProtocolGuid,
                  ImageHandle,
                  ControllerHandle
                  );
  if (EFI_ERROR (Status)) {
    return Status;
  }
  return NetLibDestroyServiceChild (
           ControllerHandle,
           ImageHandle,
           ServiceBindingGuid,
           ChildHandle
           );
}