Tuesday, February 5, 2019

Get IPv4 information via EFI_IP4_CONFIG2_PROTOCOL

This is an example for BIOS test guy in US. He asked me how to access IPv4 information via EfiPy library.

The procedure is the same as EDKII does. This sample code uses EFI_IP4_CONFIG2_PROTOCOL for example, only.
Here is the complete source code.

Samples code dumps these informations:
#
# Pseudo code
#
# IfInfo = Ip4Cfg2.EFI_IP4_CONFIG2_INTERFACE_INFO ()
# EFI_IP4_CONFIG2_PROTOCOL.GetData (
#                            Ip4Cfg2P,
#                            Ip4Cfg2.Ip4Config2DataTypeInterfaceInfo,
#                            e.byref (DataSize),
#                            e.cast (e.byref (IfInfo), e.PVOID)
#                            )
#
# Dumpped information
#
EFI_IP4_CONFIG2_INTERFACE_INFO.Name
EFI_IP4_CONFIG2_INTERFACE_INFO.IfType
EFI_IP4_CONFIG2_INTERFACE_INFO.HwAddressSize
EFI_IP4_CONFIG2_INTERFACE_INFO.HwAddress EFI_IP4_CONFIG2_INTERFACE_INFO.StationAddress
EFI_IP4_CONFIG2_INTERFACE_INFO.SubnetMask
EFI_IP4_CONFIG2_INTERFACE_INFO.RouteTableSize

And DNS informations:
#
# Pseudo code
#
# DnsAddr = (e.EFI_IPv4_ADDRESS * \
#            (DataSize.value / e.sizeof (e.EFI_IPv4_ADDRESS))) ()
# Status = Ip4Cfg2P[0].GetData (
#                        Ip4Cfg2P,
#                        Ip4Cfg2.Ip4Config2DataTypeDnsServer,
#                        e.byref (DataSize),
#                        e.cast (e.byref (DnsAddr), e.PVOID)
#                        )
#

# Dumpped information
#
# for Dns in DnsAddr:
#   print "   DnsAddr:"
#   for Addr in Dns.Addr:
#     print "%02X " % Addr,
#   print

No comments:

Post a Comment