Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

DhcpGetClientInfo (dhcpsapi)
 
.
Summary
The DhcpGetClientInfo function returns information about a specific DHCP client.

C# Signature:

/// <summary>
/// The DhcpGetClientInfo function returns information about a specific DHCP client.
/// </summary>
/// <param name="ServerIpAddress">[in] Unicode string that specifies the IP address of the DHCP server.</param>
/// <param name="SearchInfo">[in] DHCP_SEARCH_INFO structure that contains the parameters for the search. </param>
/// <param name="ClientInfo">[out] Pointer to a DHCP_CLIENT_INFO structure that contains information describing the DHCP client that most closely matches the provided search parameters. If no client is found, this parameter will be null.</param>
/// <returns>This function returns ERROR_SUCCESS upon a successful call. Otherwise, it returns one of the DHCP Server Management API Error Codes.</returns>
[DllImport("dhcpsapi.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern UInt32 DhcpGetClientInfo(
      String ServerIpAddress,
      ref DHCP_SEARCH_INFO SearchInfo,
      out IntPtr ClientInfo);

VB Signature:

Declare Function DhcpGetClientInfo Lib "dhcpsapi.dll" (TODO) As TODO

User-Defined Types:

DHCP_SEARCH_INFO

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

static void Main()
    {
        String ServerIpAddress = "192.168.0.250";

        UInt32 DHCPResult = 0;
        try
        {

        DHCP_SEARCH_INFO searchInfo = new DHCP_SEARCH_INFO();
        DHCP_SEARCH_INFO_TYPE searchInfoType = DHCP_SEARCH_INFO_TYPE.DhcpClientIpAddress;

        searchInfo.SearchType = searchInfoType;
        searchInfo.ClientIpAddress = ConvertIPAddress("192.168.0.10");

        IntPtr pClientInfo;
        DHCPResult = DhcpGetClientInfo(ServerIpAddress, ref searchInfo, out pClientInfo);
        if (DHCPResult == 0 && pClientInfo != IntPtr.Zero)
        {
            DHCP_CLIENT_INFO clientInfo = (DHCP_CLIENT_INFO)Marshal.PtrToStructure(pClientInfo, typeof(DHCP_CLIENT_INFO));
            Console.WriteLine(DHCPResult.ToString() + " Client Info: " + clientInfo.ClientName);
        }
        else
        {
            Console.WriteLine(DHCPResult.ToString() + " Failed");
        }
    }

    public static UInt32 ConvertIPAddress(string ipAddress)
    {
        char[] dot = ".".ToCharArray();
        char[] zero = "0".ToCharArray();
        string[] Octets = ipAddress.Split(dot[0]);
        string HexIP = "";

        foreach (string Octet in Octets)
        {
        HexIP += Convert.ToString(Convert.ToInt16(Octet), 16).PadLeft(2, zero[0]);
        }
        return Convert.ToUInt32(HexIP, 16);
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions