Skip to content

Instantly share code, notes, and snippets.

@rcook
Last active March 30, 2020 05:46
Show Gist options
  • Save rcook/8603834 to your computer and use it in GitHub Desktop.
Save rcook/8603834 to your computer and use it in GitHub Desktop.
public struct DHCPCAPI_IP_ADDRESS
{
public byte Value0;
public byte Value1;
public byte Value2;
public byte Value3;
}
public struct DHCPCAPI_PARAMS
{
public uint Flags;
public OPTION OptionId;
[MarshalAs(UnmanagedType.Bool)]
public bool IsVendor;
public IntPtr Data;
public uint nBytesData;
}
public struct DHCPCAPI_PARAMS_ARRAY
{
public uint nParams;
public IntPtr Params;
}
[Flags]
public enum DHCPCAPI_REQUEST : uint
{
PERSISTENT = 1u,
SYNCHRONOUS = 2u,
ASYNCHRONOUS = 4u,
CANCEL = 8u,
MASK = 15u
}
The MIT License (MIT)
Copyright (c) 2013 Richard Cook
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public static class NativeMethods
{
[DllImport("dhcpcsvc.dll")]
public static extern uint DhcpCApiInitialize(out uint Version);
[DllImport("dhcpcsvc.dll")]
public static extern void DhcpCApiCleanup();
[DllImport("dhcpcsvc.dll", CharSet = CharSet.Unicode)]
public static extern uint DhcpRequestParams(
DHCPCAPI_REQUEST Flags,
IntPtr Reserved,
string AdapterName,
IntPtr ClassId,
DHCPCAPI_PARAMS_ARRAY SendParams,
DHCPCAPI_PARAMS_ARRAY RecdParams,
IntPtr Buffer,
ref uint pSize,
string RequestIdStr);
}
public enum OPTION : uint
{
NAME = 102u,
PAD = 0u,
SUBNET_MASK = 1u,
TIME_OFFSET = 2u,
ROUTER_ADDRESS = 3u,
TIME_SERVERS = 4u,
IEN116_NAME_SERVERS = 5u,
DOMAIN_NAME_SERVERS = 6u,
LOG_SERVERS = 7u,
COOKIE_SERVERS = 8u,
LPR_SERVERS = 9u,
IMPRESS_SERVERS = 10u,
RLP_SERVERS = 11u,
HOST_NAME = 12u,
BOOT_FILE_SIZE = 13u,
MERIT_DUMP_FILE = 14u,
DOMAIN_NAME = 15u,
SWAP_SERVER = 16u,
ROOT_DISK = 17u,
EXTENSIONS_PATH = 18u
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment