using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// Items from Dhcpcsvc6.dll and Dhcpcsvc.dll.
public static partial class Dhcp
{
/// De-register handle that is an event
public const uint DHCPCAPI_DEREGISTER_HANDLE_EVENT = 0x01;
/// Handle returned is to an event
public const uint DHCPCAPI_REGISTER_HANDLE_EVENT = 0x01;
private const string Lib_Dhcp = "dhcpcsvc.dll";
///
/// DHCP options. See ISC DHCP 4.4 Manual Pages -
/// dhcp-options for some details.
///
[PInvokeData("dhcpcsdk.h")]
public enum DHCP_OPTION_ID : uint
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
OPTION_PAD = 0,
OPTION_SUBNET_MASK = 1,
OPTION_TIME_OFFSET = 2,
OPTION_ROUTER_ADDRESS = 3,
OPTION_TIME_SERVERS = 4,
OPTION_IEN116_NAME_SERVERS = 5,
OPTION_DOMAIN_NAME_SERVERS = 6,
OPTION_LOG_SERVERS = 7,
OPTION_COOKIE_SERVERS = 8,
OPTION_LPR_SERVERS = 9,
OPTION_IMPRESS_SERVERS = 10,
OPTION_RLP_SERVERS = 11,
OPTION_HOST_NAME = 12,
OPTION_BOOT_FILE_SIZE = 13,
OPTION_MERIT_DUMP_FILE = 14,
OPTION_DOMAIN_NAME = 15,
OPTION_SWAP_SERVER = 16,
OPTION_ROOT_DISK = 17,
OPTION_EXTENSIONS_PATH = 18,
OPTION_BE_A_ROUTER = 19,
OPTION_NON_LOCAL_SOURCE_ROUTING = 20,
OPTION_POLICY_FILTER_FOR_NLSR = 21,
OPTION_MAX_REASSEMBLY_SIZE = 22,
OPTION_DEFAULT_TTL = 23,
OPTION_PMTU_AGING_TIMEOUT = 24,
OPTION_PMTU_PLATEAU_TABLE = 25,
OPTION_MTU = 26,
OPTION_ALL_SUBNETS_MTU = 27,
OPTION_BROADCAST_ADDRESS = 28,
OPTION_PERFORM_MASK_DISCOVERY = 29,
OPTION_BE_A_MASK_SUPPLIER = 30,
OPTION_PERFORM_ROUTER_DISCOVERY = 31,
OPTION_ROUTER_SOLICITATION_ADDR = 32,
OPTION_STATIC_ROUTES = 33,
OPTION_TRAILERS = 34,
OPTION_ARP_CACHE_TIMEOUT = 35,
OPTION_ETHERNET_ENCAPSULATION = 36,
OPTION_TTL = 37,
OPTION_KEEP_ALIVE_INTERVAL = 38,
OPTION_KEEP_ALIVE_DATA_SIZE = 39,
OPTION_NETWORK_INFO_SERVICE_DOM = 40,
OPTION_NETWORK_INFO_SERVERS = 41,
OPTION_NETWORK_TIME_SERVERS = 42,
OPTION_VENDOR_SPEC_INFO = 43,
OPTION_NETBIOS_NAME_SERVER = 44,
OPTION_NETBIOS_DATAGRAM_SERVER = 45,
OPTION_NETBIOS_NODE_TYPE = 46,
OPTION_NETBIOS_SCOPE_OPTION = 47,
OPTION_XWINDOW_FONT_SERVER = 48,
OPTION_XWINDOW_DISPLAY_MANAGER = 49,
OPTION_REQUESTED_ADDRESS = 50,
OPTION_LEASE_TIME = 51,
OPTION_OK_TO_OVERLAY = 52,
OPTION_MESSAGE_TYPE = 53,
OPTION_SERVER_IDENTIFIER = 54,
OPTION_PARAMETER_REQUEST_LIST = 55,
OPTION_MESSAGE = 56,
OPTION_MESSAGE_LENGTH = 57,
OPTION_RENEWAL_TIME = 58,
OPTION_REBIND_TIME = 59,
OPTION_CLIENT_CLASS_INFO = 60,
OPTION_CLIENT_ID = 61,
OPTION_TFTP_SERVER_NAME = 66,
OPTION_BOOTFILE_NAME = 67,
OPTION_MSFT_IE_PROXY = 252,
OPTION_END = 255,
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
/// Flags that specify the data being requested.
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpRequestParams")]
[Flags]
public enum DHCPCAPI_REQUEST
{
/// The request is persisted but no options are fetched.
DHCPCAPI_REQUEST_PERSISTENT = 0x01,
/// Options will be fetched from the server.
DHCPCAPI_REQUEST_SYNCHRONOUS = 0x02,
/// Request and return, set event on completion.
DHCPCAPI_REQUEST_ASYNCHRONOUS = 0x04,
/// Cancel request.
DHCPCAPI_REQUEST_CANCEL = 0x08,
}
///
/// The DhcpCApiCleanup function enables DHCP to properly clean up resources allocated throughout the use of DHCP function
/// calls. The DhcpCApiCleanup function must only be called if a previous call to DhcpCApiInitialize executed successfully.
///
/// None
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcpcapicleanup void DhcpCApiCleanup();
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpCApiCleanup")]
public static extern void DhcpCApiCleanup();
///
/// The DhcpCApiInitialize function must be the first function call made by users of DHCP; it prepares the system for all
/// other DHCP function calls. Other DHCP functions should only be called if the DhcpCApiInitialize function executes successfully.
///
/// Pointer to the DHCP version implemented by the client.
/// Returns ERROR_SUCCESS upon successful completion.
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcpcapiinitialize DWORD DhcpCApiInitialize( LPDWORD
// Version );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpCApiInitialize")]
public static extern Win32Error DhcpCApiInitialize(out uint Version);
///
/// The DhcpDeRegisterParamChange function releases resources associated with previously registered event notifications, and
/// closes the associated event handle.
///
/// Reserved. Must be set to zero.
/// Reserved. Must be set to NULL.
///
/// Must be the same value as the HANDLE variable in the DhcpRegisterParamChange function call for which the client is
/// deregistering event notification.
///
/// Returns ERROR_SUCCESS upon successful completion. Otherwise, returns Windows error codes.
///
/// The DhcpDeRegisterParamChange function must be made subsequent to an associated DhcpRegisterParamChange function call,
/// and the Flags parameter and the HANDLE variable passed in the Event parameter to DhcpDeRegisterParamChange must
/// match corresponding Flags parameter and the HANDLE variable of the previous and associated DhcpRegisterParamChange
/// function call.
///
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcpderegisterparamchange DWORD
// DhcpDeRegisterParamChange( DWORD Flags, LPVOID Reserved, LPVOID Event );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpDeRegisterParamChange")]
public static extern Win32Error DhcpDeRegisterParamChange([Optional] uint Flags, [Optional] IntPtr Reserved, HEVENT Event);
/// The DhcpGetOriginalSubnetMask is used to get the subnet mask of any given adapter name.
/// [in] Contains the name of the local DHCP-enabled adapter for which the subnet mask is being retrieved.
/// [out] Pointer to the retrieved subnet mask.
///
/// This function always returns 0.
/// Failure is indicated by a return value of 0 for the dwSubnetMask parameter.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// Returned if the sAdapterName parameter is invalid.
///
///
///
// https://docs.microsoft.com/en-us/previous-versions/bb656318(v=vs.85)
// void APIENTRY DhcpGetOriginalSubnetMask( __in LPCWSTR sAdapterName, __out DWORD *dwSubnetMask );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("Dhcpcsdk.h")]
public static extern void DhcpGetOriginalSubnetMask([MarshalAs(UnmanagedType.LPWStr)] string sAdapterName, out DHCP_IP_ADDRESS dwSubnetMask);
///
/// The DhcpRegisterParamChange function enables clients to register for notification of changes in DHCP configuration parameters.
///
///
/// Reserved. Must be set to DHCPCAPI_REGISTER_HANDLE_EVENT. If it is not set to this flag value, the API call will not be successful.
///
/// Reserved. Must be set to NULL.
/// GUID of the adapter for which event notification is being requested. Must be under 256 characters.
/// Reserved. Must be set to NULL.
///
/// Parameters for which the client is interested in registering for notification, in the form of a DHCPCAPI_PARAMS_ARRAY structure.
///
///
/// Attributes of Handle are determined by the value of Flags. In version 2 of the DHCP API, Flags must be set to
/// DHCPCAPI_REGISTER_HANDLE_EVENT, and therefore, Handle must be a pointer to a HANDLE variable that will hold the handle to
/// a Windows event that gets signaled when parameters specified in Params change. Note that this HANDLE variable is used in
/// a subsequent call to the DhcpDeRegisterParamChange function to deregister event notifications associated with this
/// particular call to the DhcpRegisterParamChange function.
///
///
/// Returns ERROR_SUCCESS upon successful completion. Otherwise, returns Windows error codes.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// Returned if the AdapterName parameter is over 256 characters long.
///
///
///
///
/// Version 2 of the DHCP Client API provides only event-based notification. With event-based notification in DHCP, clients enable
/// notification by having Handle point to a variable that, upon successful return, holds the EVENT handles that are signaled
/// whenever changes occur to the parameters requested in Params.
///
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcpregisterparamchange DWORD DhcpRegisterParamChange(
// DWORD Flags, LPVOID Reserved, LPWSTR AdapterName, LPDHCPCAPI_CLASSID ClassId, DHCPCAPI_PARAMS_ARRAY Params, LPVOID Handle );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpRegisterParamChange")]
public static extern Win32Error DhcpRegisterParamChange(uint Flags, [Optional] IntPtr Reserved, [MarshalAs(UnmanagedType.LPWStr)] string AdapterName,
[Optional] IntPtr ClassId, DHCPCAPI_PARAMS_ARRAY Params, out HEVENT Handle);
/// The DhcpRemoveDNSRegistrations function removes all DHCP-initiated DNS registrations for the client.
/// Returns ERROR_SUCCESS upon successful completion.
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcpremovednsregistrations DWORD DhcpRemoveDNSRegistrations();
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpRemoveDNSRegistrations")]
public static extern Win32Error DhcpRemoveDNSRegistrations();
///
/// The DhcpRequestParams function enables callers to synchronously, or synchronously and persistently obtain DHCP data from
/// a DHCP server.
///
///
///
/// Flags that specify the data being requested. This parameter is optional. The following possible values are supported and are not
/// mutually exclusive:
///
///
///
/// Value
/// Meaning
///
/// -
/// DHCPCAPI_REQUEST_PERSISTENT
/// The request is persisted but no options are fetched.
///
/// -
/// DHCPCAPI_REQUEST_SYNCHRONOUS
/// Options will be fetched from the server.
///
///
///
/// Reserved for future use. Must be set to NULL.
/// GUID of the adapter on which requested data is being made. Must be under 256 characters.
///
/// Class identifier (ID) that should be used if DHCP INFORM messages are being transmitted onto the network. This parameter is optional.
///
///
/// Optional data to be requested, in addition to the data requested in the RecdParams array. The SendParams parameter cannot
/// contain any of the standard options that the DHCP client sends by default.
///
///
/// Array of DHCP data the caller is interested in receiving. This array must be empty prior to the DhcpRequestParams
/// function call.
///
/// Buffer used for storing the data associated with requests made in RecdParams.
///
/// Size of Buffer.
///
/// Required size of the buffer, if it is insufficiently sized to hold the data, otherwise indicates size of the buffer which was
/// successfully filled.
///
///
///
/// Application identifier (ID) used to facilitate a persistent request. Must be a printable string with no special characters
/// (commas, backslashes, colons, or other illegal characters may not be used). The specified application identifier (ID) is used in
/// a subsequent DhcpUndoRequestParams function call to clear the persistent request, as necessary.
///
///
/// Returns ERROR_SUCCESS upon successful completion.
///
/// Upon return, RecdParams is filled with pointers to requested data, with corresponding data placed in Buffer. If pSize indicates
/// that Buffer has insufficient space to store returned data, the DhcpRequestParams function returns ERROR_MORE_DATA, and
/// returns the required buffer size in pSize. Note that the required size of Buffer may increase during the time that elapses
/// between the initial function call's return and a subsequent call; therefore, the required size of Buffer (indicated in pSize)
/// provides an indication of the approximate size required of Buffer, rather than guaranteeing that subsequent calls will return
/// successfully if Buffer is set to the size indicated in pSize.
///
/// Other errors return appropriate Windows error codes.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// Returned if the AdapterName parameter is over 256 characters long.
///
/// -
/// ERROR_BUFFER_OVERFLOW
/// Returned if the AdapterName parameter is over 256 characters long.
///
///
///
///
///
/// DHCP clients store data obtained from a DHCP server in their local cache. If the DHCP client cache contains all data requested
/// in the RecdParams array of a DhcpRequestParams function call, the client returns data from its cache. If requested data
/// is not available in the client cache, the client processes the DhcpRequestParams function call by submitting a
/// DHCP-INFORM message to the DHCP server.
///
///
/// When the client submits a DHCP-INFORM message to the DHCP server, it includes any requests provided in the optional SendParams
/// parameter, and provides the Class identifier (ID) specified in the ClassId parameter, if provided.
///
///
/// Clients can also specify that DHCP data be retrieved from the DHCP server each time the DHCP client boots, which is considered a
/// persistent request. To enable persistent requests, the caller must specify the RequestIdStr parameter, and also specify the
/// additional DHCPAPI_REQUEST_PERSISTENT flag in the dwFlags parameter. This persistent request capability is especially
/// useful when clients need to automatically request application-critical information at each boot. To disable a persist request,
/// clients must call the function.
///
///
/// Note The callers of this API must not make blocking calls to this API, since it can take up to a maximum of 2 minutes to
/// return a code or status. UI behaviors in particular should not block on the return of this call, since it can introduce a
/// significant delay in UI response time.
///
/// For more information about DHCP INFORM messages, and other standards-based information about DHCP, consult DHCP Standards.
/// To see the DhcpRequestParams function in use, see DHCP Examples.
///
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcprequestparams DWORD DhcpRequestParams( DWORD Flags,
// LPVOID Reserved, LPWSTR AdapterName, LPDHCPCAPI_CLASSID ClassId, DHCPCAPI_PARAMS_ARRAY SendParams, DHCPCAPI_PARAMS_ARRAY
// RecdParams, LPBYTE Buffer, LPDWORD pSize, LPWSTR RequestIdStr );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpRequestParams")]
public static extern Win32Error DhcpRequestParams([Optional] DHCPCAPI_REQUEST Flags, [In, Optional] IntPtr Reserved, [MarshalAs(UnmanagedType.LPWStr)] string AdapterName,
in DHCPCAPI_CLASSID ClassId, DHCPCAPI_PARAMS_ARRAY SendParams, DHCPCAPI_PARAMS_ARRAY RecdParams, [Out] IntPtr Buffer, ref uint pSize, [Optional, MarshalAs(UnmanagedType.LPWStr)] string RequestIdStr);
///
/// The DhcpRequestParams function enables callers to synchronously, or synchronously and persistently obtain DHCP data from
/// a DHCP server.
///
///
///
/// Flags that specify the data being requested. This parameter is optional. The following possible values are supported and are not
/// mutually exclusive:
///
///
///
/// Value
/// Meaning
///
/// -
/// DHCPCAPI_REQUEST_PERSISTENT
/// The request is persisted but no options are fetched.
///
/// -
/// DHCPCAPI_REQUEST_SYNCHRONOUS
/// Options will be fetched from the server.
///
///
///
/// Reserved for future use. Must be set to NULL.
/// GUID of the adapter on which requested data is being made. Must be under 256 characters.
///
/// Class identifier (ID) that should be used if DHCP INFORM messages are being transmitted onto the network. This parameter is optional.
///
///
/// Optional data to be requested, in addition to the data requested in the RecdParams array. The SendParams parameter cannot
/// contain any of the standard options that the DHCP client sends by default.
///
///
/// Array of DHCP data the caller is interested in receiving. This array must be empty prior to the DhcpRequestParams
/// function call.
///
/// Buffer used for storing the data associated with requests made in RecdParams.
///
/// Size of Buffer.
///
/// Required size of the buffer, if it is insufficiently sized to hold the data, otherwise indicates size of the buffer which was
/// successfully filled.
///
///
///
/// Application identifier (ID) used to facilitate a persistent request. Must be a printable string with no special characters
/// (commas, backslashes, colons, or other illegal characters may not be used). The specified application identifier (ID) is used in
/// a subsequent DhcpUndoRequestParams function call to clear the persistent request, as necessary.
///
///
/// Returns ERROR_SUCCESS upon successful completion.
///
/// Upon return, RecdParams is filled with pointers to requested data, with corresponding data placed in Buffer. If pSize indicates
/// that Buffer has insufficient space to store returned data, the DhcpRequestParams function returns ERROR_MORE_DATA, and
/// returns the required buffer size in pSize. Note that the required size of Buffer may increase during the time that elapses
/// between the initial function call's return and a subsequent call; therefore, the required size of Buffer (indicated in pSize)
/// provides an indication of the approximate size required of Buffer, rather than guaranteeing that subsequent calls will return
/// successfully if Buffer is set to the size indicated in pSize.
///
/// Other errors return appropriate Windows error codes.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// Returned if the AdapterName parameter is over 256 characters long.
///
/// -
/// ERROR_BUFFER_OVERFLOW
/// Returned if the AdapterName parameter is over 256 characters long.
///
///
///
///
///
/// DHCP clients store data obtained from a DHCP server in their local cache. If the DHCP client cache contains all data requested
/// in the RecdParams array of a DhcpRequestParams function call, the client returns data from its cache. If requested data
/// is not available in the client cache, the client processes the DhcpRequestParams function call by submitting a
/// DHCP-INFORM message to the DHCP server.
///
///
/// When the client submits a DHCP-INFORM message to the DHCP server, it includes any requests provided in the optional SendParams
/// parameter, and provides the Class identifier (ID) specified in the ClassId parameter, if provided.
///
///
/// Clients can also specify that DHCP data be retrieved from the DHCP server each time the DHCP client boots, which is considered a
/// persistent request. To enable persistent requests, the caller must specify the RequestIdStr parameter, and also specify the
/// additional DHCPAPI_REQUEST_PERSISTENT flag in the dwFlags parameter. This persistent request capability is especially
/// useful when clients need to automatically request application-critical information at each boot. To disable a persist request,
/// clients must call the function.
///
///
/// Note The callers of this API must not make blocking calls to this API, since it can take up to a maximum of 2 minutes to
/// return a code or status. UI behaviors in particular should not block on the return of this call, since it can introduce a
/// significant delay in UI response time.
///
/// For more information about DHCP INFORM messages, and other standards-based information about DHCP, consult DHCP Standards.
/// To see the DhcpRequestParams function in use, see DHCP Examples.
///
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcprequestparams DWORD DhcpRequestParams( DWORD Flags,
// LPVOID Reserved, LPWSTR AdapterName, LPDHCPCAPI_CLASSID ClassId, DHCPCAPI_PARAMS_ARRAY SendParams, DHCPCAPI_PARAMS_ARRAY
// RecdParams, LPBYTE Buffer, LPDWORD pSize, LPWSTR RequestIdStr );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpRequestParams")]
public static extern Win32Error DhcpRequestParams([Optional] DHCPCAPI_REQUEST Flags, [In, Optional] IntPtr Reserved, [MarshalAs(UnmanagedType.LPWStr)] string AdapterName,
[In, Optional] IntPtr ClassId, DHCPCAPI_PARAMS_ARRAY SendParams, DHCPCAPI_PARAMS_ARRAY RecdParams, [Out] IntPtr Buffer, ref uint pSize, [Optional, MarshalAs(UnmanagedType.LPWStr)] string RequestIdStr);
///
/// The DhcpUndoRequestParams function removes persistent requests previously made with a DhcpRequestParams function call.
///
/// Reserved. Must be zero.
/// Reserved for future use. Must be set to NULL.
///
/// GUID of the adapter for which information is no longer required. Must be under 256 characters.
/// Note This parameter is no longer used.
///
///
/// Application identifier (ID) originally used to make a persistent request. This string must match the RequestIdStr parameter used
/// in the DhcpRequestParams function call that obtained the corresponding persistent request. Note that this must match the
/// previous application identifier (ID) used, and must be a printable string with no special characters (commas, backslashes,
/// colons, or other illegal characters may not be used).
///
/// Returns ERROR_SUCCESS upon successful completion. Otherwise, returns a Windows error code.
///
/// Persistent requests are typically made by the setup or installer process associated with the application. When appropriate, the
/// setup or installer process would likely make the DhcpUndoRequestParams function call to cancel its associated persistent request.
///
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/nf-dhcpcsdk-dhcpundorequestparams DWORD DhcpUndoRequestParams( DWORD
// Flags, LPVOID Reserved, LPWSTR AdapterName, LPWSTR RequestIdStr );
[DllImport(Lib_Dhcp, SetLastError = false, ExactSpelling = true)]
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NF:dhcpcsdk.DhcpUndoRequestParams")]
public static extern Win32Error DhcpUndoRequestParams([Optional] uint Flags, [In, Optional] IntPtr Reserved, [MarshalAs(UnmanagedType.LPWStr)] string AdapterName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string RequestIdStr);
/// Represents an 8-byte IP v4 address.
[PInvokeData("dhcpsapi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct DHCP_IP_ADDRESS
{
/// The underlying value.
public uint value;
/// Initializes a new instance of the struct from a UInt32/DWORD.
/// The value.
public DHCP_IP_ADDRESS(uint val = 0) => value = val;
/// Initializes a new instance of the struct from an .
/// The value.
///
public DHCP_IP_ADDRESS(System.Net.IPAddress ipaddr)
{
if (ipaddr is null) value = 0;
if (ipaddr.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork)
throw new InvalidCastException();
#pragma warning disable CS0618 // Type or member is obsolete
value = (uint)ipaddr.Address;
#pragma warning restore CS0618 // Type or member is obsolete
}
/// Performs an explicit conversion from to .
/// The DWORD based address.
/// The resulting instance from the conversion.
public static explicit operator System.Net.IPAddress(DHCP_IP_ADDRESS addr) =>
new System.Net.IPAddress(BitConverter.GetBytes(addr.value));
/// Performs an implicit conversion from to .
/// The value.
/// The resulting instance from the conversion.
public static implicit operator DHCP_IP_ADDRESS(System.Net.IPAddress addr) => new DHCP_IP_ADDRESS(addr);
/// Performs an implicit conversion from to .
/// The address as four bytes.
/// The resulting instance from the conversion.
public static implicit operator DHCP_IP_ADDRESS(uint addr) => new DHCP_IP_ADDRESS(addr);
/// Converts this address to standard notation.
/// A that represents this instance.
public override string ToString() => ((System.Net.IPAddress)this).ToString();
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public override int GetHashCode() => value.GetHashCode();
}
/// The DHCPAPI_PARAMS structure is used to request DHCP parameters.
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/ns-dhcpcsdk-dhcpapi_params typedef struct _DHCPAPI_PARAMS { ULONG
// Flags; ULONG OptionId; BOOL IsVendor; #if ... LPBYTE Data; #else LPBYTE Data; #endif DWORD nBytesData; } DHCPAPI_PARAMS,
// *PDHCPAPI_PARAMS, *LPDHCPAPI_PARAMS, DHCPCAPI_PARAMS, *PDHCPCAPI_PARAMS, *LPDHCPCAPI_PARAMS;
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NS:dhcpcsdk._DHCPAPI_PARAMS")]
[StructLayout(LayoutKind.Sequential)]
public struct DHCPAPI_PARAMS
{
/// Reserved. Must be set to zero.
public uint Flags;
/// Identifier for the DHCP parameter being requested.
public DHCP_OPTION_ID OptionId;
/// Specifies whether the DHCP parameter is vendor-specific. Set to TRUE if the parameter is vendor-specific.
[MarshalAs(UnmanagedType.Bool)]
public bool IsVendor;
/// Pointer to the parameter data.
public IntPtr Data;
/// Size of the data pointed to by Data, in bytes.
public uint nBytesData;
}
/// The DHCPCAPI_CLASSID structure defines a client Class ID.
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/ns-dhcpcsdk-dhcpcapi_classid typedef struct _DHCPCAPI_CLASSID { ULONG
// Flags; #if ... LPBYTE Data; #else LPBYTE Data; #endif ULONG nBytesData; } DHCPCAPI_CLASSID, *PDHCPCAPI_CLASSID, *LPDHCPCAPI_CLASSID;
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NS:dhcpcsdk._DHCPCAPI_CLASSID")]
[StructLayout(LayoutKind.Sequential)]
public struct DHCPCAPI_CLASSID
{
/// Reserved. Must be set to zero.
public uint Flags;
/// Class ID binary data.
public IntPtr Data;
/// Size of Data, in bytes.
public uint nBytesData;
}
/// The DHCPCAPI_PARAMS_ARRAY structure stores an array of DHCPAPI_PARAMS structures used to query DHCP parameters.
// https://docs.microsoft.com/en-us/windows/win32/api/dhcpcsdk/ns-dhcpcsdk-dhcpcapi_params_array typedef struct
// _DHCPCAPI_PARAMS_ARARAY { ULONG nParams; #if ... LPDHCPCAPI_PARAMS Params; #else LPDHCPCAPI_PARAMS Params; #endif }
// DHCPCAPI_PARAMS_ARRAY, *PDHCPCAPI_PARAMS_ARRAY, *LPDHCPCAPI_PARAMS_ARRAY;
[PInvokeData("dhcpcsdk.h", MSDNShortId = "NS:dhcpcsdk._DHCPCAPI_PARAMS_ARARAY")]
[StructLayout(LayoutKind.Sequential)]
public struct DHCPCAPI_PARAMS_ARRAY
{
/// Number of elements in the Params array.
public uint nParams;
/// Array of DHCPAPI_PARAMS structures.
public IntPtr Params;
}
}
}