4.4 Enumerating the DHCP Client in a Subnet
In this example, the DHCP server has assigned 120 IP address leases to clients from a specific DHCPv4 scope. This example illustrates how to enumerate the list of DHCP clients that have been assigned an active IP address lease from a DHCPv4 scope by the DHCP server.
The client calls the RPC method R_DhcpEnumSubnetClients (section 3.1.4.21) with the following parameters:
An endpoint of the DHCP server as the server IP address.
The IPv4 address of the scope is set as the subnet address.
Zero as the handle to the location in the list of DHCP clients assigned an address from the specified scope in order to request data from the beginning of the data set.
The next field can be set to 1,024 bytes as the preferred maximum amount of data to return.
A pointer of type LPDHCP_CLIENT_INFO_ARRAY (section 2.2.1.2.13) to a structure that contains a pointer to an array of DHCP_CLIENT_INFO (section 2.2.1.2.12) and the number of elements in which the information about the DHCP clients will be returned.
An allocated pointer to ClientsRead, a DWORD that will contain the number of DHCP clients whose information is being returned.
An allocated pointer to ClientsTotal, a DWORD that will contain the number of DHCP clients remaining that have an active IP address lease obtained from the specified scope whose information is still to be returned.
The client calls the RPC method, which returns ERROR_SUCCESS and updates the following parameters:
The pointer of type LPDHCP_CLIENT_INFO_ARRAY is updated with a buffer containing 1,024 bytes of information about clients that have obtained an IP address lease from the specified scope.
The handle to the location on the DHCP server from which the DHCP server will return data about the remaining clients whose information is still to be retrieved.
The ClientsRead DWORD is updated with the number of DHCP clients whose information is included in the buffer of type LPDHCP_CLIENT_INFO_ARRAY.
The ClientsTotal DWORD is updated with the value (150 – ClientsRead), which is the number of clients whose information is still to be retrieved.
The client again invokes the RPC method R_DhcpEnumSubnetClients with the same parameters as before except for the following:
The updated handle received from the previous call to the RPC method is passed in as the handle to the location from which the DHCP server will return data in this invocation.
In this manner, the client can retrieve information about all the DHCP clients that have obtained an IP address lease from the specified DHCPv4 scope on the DHCP server.
After the client no longer needs the list of enumerated DHCP clients, it frees the memory pointed to by LPDHCP_CLIENT_INFO_ARRAY by calling the function midl_user_free (see section 3).