Skip to main content

 none
Issue with DhcpEnumSubnetClientsV6 method of the Microsoft DHCP management API (DHCPM) RRS feed

  • Question

  • Hi,

    I'm trying to enumerate the IPv6 leases on a Microsoft DHCP server using the DhcpEnumSubnetClientsV6 method.

    I have correctly gotten the subnet addresses using the method DhcpEnumSubnetsV6 and then passed them into other methods such as DhcpGetAllOptionValuesV6 so I don't see why DhcpEnumSubnetClientsV6  is returning an error

    Win32 error 2 - "The system cannot find the file specified".

    This would suggest that the subnet doesn't exist (but it does because the other methods are happy).

    I can't see why the SubnetAddress property for this method would be different to those. Help!

    ///<summary>

    /// The DhcpEnumSubnetClientsV6 function returns an enumerated list of clients with served IP addresses in the specified subnet.

    ///</summary>

    ///<remarks>http://msdn.microsoft.com/en-us/library/windows/desktop/bb871558(v=vs.85).aspx</remarks>

    [DllImport("dhcpsapi.dll", SetLastError =true, CharSet = CharSet.Auto)]

    protectedstatic extern uint DhcpEnumSubnetClientsV6(

       String ServerIpAddress,

       DHCP_IPV6_ADDRESS SubnetAddress,

       ref uint ResumeHandle,

       uint PreferredMaximum,

       out IntPtr ClientInfo,

       ref uint ClientsRead,

       ref uint ClientsTotal

    );

    privatevoid GetLeases()

    {

       uint ResumeHandle = 0;

       uint ClientsRead = 0;

       uint ClientsTotal = 0;

       IntPtr ClientInfoPointer = IntPtr.Zero;

       DHCP_IPV6_ADDRESS SubnetAddress = new DHCP_IPV6_ADDRESS();

        SubnetAddress.HighOrderBits = 2308098004483047424;             //  <- I got this from DhcpEnumSubnetsV6 so should be good!

       SubnetAddress.LowOrderBits = 0;

       uint ReturnValue = DhcpEnumSubnetClientsV6("demo-dhcp-2k8", SubnetAddress,ref ResumeHandle, uint.MaxValue,out ClientInfoPointer,    ref ClientsRead, ref ClientsTotal);

       if (ReturnValue != 259) throw new Win32Exception(Convert.ToInt32(ReturnValue));

    }

    ///<summary>

    /// The DHCP_IPV6_ADDRESS structure contains an IPv6 address. As this is a 128bit address this is split into two ulong (64bit) address parts.

    ///</summary>

    ///<remarks>http://msdn.microsoft.com/en-us/library/windows/desktop/dd897589(v=vs.85).aspx</remarks>

    [StructLayout(LayoutKind.Sequential)]

    publicstruct DHCP_IPV6_ADDRESS

    {

       /// <summary>

       /// A value containing the higher 64 bits of the IPv6 address.

       /// </summary>

       public ulong HighOrderBits;

       /// <summary>

       /// A value containing the lower 64 bits of the IPv6 address.

       /// </summary>

       public ulong LowOrderBits;

    }

    Thanks,

    Dave

    Automated Network Documentation


    David Homer

    Friday, May 18, 2012 7:54 AM

All replies

  • Hi David.

    The ResumeHandle parameter must be of type DHCP_IPV6_ADDRESS:

    [DllImport("dhcpsapi.dll", SetLastError =true, CharSet = CharSet.Auto)]

    protectedstatic extern uint DhcpEnumSubnetClientsV6(

       String ServerIpAddress,

       DHCP_IPV6_ADDRESS SubnetAddress,

       ref DHCP_IPV6_ADDRESS ResumeHandle,

       uint PreferredMaximum,

       out IntPtr ClientInfo,

       ref uint ClientsRead,

       ref uint ClientsTotal

    );

    best regards
    Oliver



    Friday, October 26, 2018 10:44 AM