4.12 Enumerating the DHCPv6 Client in a Subnet

In this example, the DHCP server has assigned 120 IPv6 address leases to clients from a specific DHCPv6 scope. This example illustrates how to enumerate the list of DHCP clients that have been assigned an active IPv6 address lease from a DHCPv6 scope by the DHCP server.

The client calls the RPC method R_DhcpEnumSubnetClientsV6 (section 3.2.4.65) with the following parameters:

  • An endpoint of the DHCP server as the server IP address. This parameter is optional and can be passed as a pointer to a null Unicode string.

  • The IPv6 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, ClientInfo, of type LPDHCP_CLIENT_INFO_ARRAY_V6 to a structure that contains a pointer to an array of DHCP_CLIENT_INFO_V6 structures and the number of elements in the array in which the information about the DHCPv6 clients will be returned.

  • An allocated pointer, ClientsRead, to a DWORD that will contain the number of DHCPv6 clients whose information is being returned.

  • An allocated pointer, ClientsTotal, to 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, ClientInfo, of type LPDHCP_CLIENT_INFO_ARRAY_V6 is updated with a buffer containing 1,024 bytes of information about clients that have obtained an IPv6 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 parameter pointer to a DWORD is updated with the number of DHCPv6 clients whose information is included in the buffer of type LPDHCP_CLIENT_INFO_ARRAY_V6.

  • The ClientsTotal parameter pointer to a DWORD is updated with the value (150 –ClientsRead), which is the number of clients whose information is still to be retrieved.

The client frees the memory pointed to by the pointer ClientInfo of type LPDHCP_CLIENT_INFO_ARRAY_V6 by calling the function midl_user_free (section 3).

The client again invokes the RPC method R_DhcpEnumSubnetClientsV6 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 DHCPv6 clients that have obtained an IPv6 address lease from the specified DHCPv6 scope on the DHCPv6 server.

Upon a successful call, after the client no longer needs the list of enumerated DHCP clients, the client frees the memory pointed to by the pointer ClientInfo of type LPDHCP_CLIENT_INFO_ARRAY_V6 by calling the function midl_user_free (section 3).