internal static IEnumerable <DhcpServerOption> GetAllOptions(DhcpServer Server) { IntPtr optionsPtr; var result = Api.DhcpGetAllOptions(Server.ipAddress.ToString(), 0, out optionsPtr); if (result != DhcpErrors.SUCCESS) { throw new DhcpServerException("DhcpGetAllOptions", result); } try { var bytes = new byte[64]; Marshal.Copy(optionsPtr, bytes, 0, 64); var options = (DHCP_ALL_OPTIONS)Marshal.PtrToStructure(optionsPtr, typeof(DHCP_ALL_OPTIONS)); foreach (var option in options.NonVendorOptions.Options) { yield return(DhcpServerOption.FromNative(Server, option, null, null)); } foreach (var option in options.VendorOptions) { yield return(DhcpServerOption.FromNative(Server, option)); } } finally { Api.DhcpRpcFreeMemory(optionsPtr); } }
private static IEnumerable <DhcpServerOption> EnumOptionsV5(DhcpServer Server, string ClassName, string VendorName) { IntPtr enumInfoPtr; int elementsRead, elementsTotal; IntPtr resumeHandle = IntPtr.Zero; uint flags = VendorName == null ? 0 : Constants.DHCP_FLAGS_OPTION_IS_VENDOR; var result = Api.DhcpEnumOptionsV5(Server.ipAddress.ToString(), flags, ClassName, VendorName, ref resumeHandle, 0xFFFFFFFF, out enumInfoPtr, out elementsRead, out elementsTotal); if (result == DhcpErrors.ERROR_NO_MORE_ITEMS || result == DhcpErrors.EPT_S_NOT_REGISTERED) { yield break; } if (result != DhcpErrors.SUCCESS && result != DhcpErrors.ERROR_MORE_DATA) { throw new DhcpServerException("DhcpEnumOptions", result); } if (elementsRead == 0) { yield break; } try { var enumInfo = (DHCP_OPTION_ARRAY)Marshal.PtrToStructure(enumInfoPtr, typeof(DHCP_OPTION_ARRAY)); foreach (var option in enumInfo.Options) { yield return(DhcpServerOption.FromNative(Server, option, VendorName, ClassName)); } } finally { Api.DhcpRpcFreeMemory(enumInfoPtr); } }
private static DhcpServerOption GetOptionV5(DhcpServer Server, int OptionId, string ClassName, string VendorName) { IntPtr optionPtr; uint flags = VendorName == null ? 0 : Constants.DHCP_FLAGS_OPTION_IS_VENDOR; var result = Api.DhcpGetOptionInfoV5(Server.ipAddress.ToString(), flags, OptionId, ClassName, VendorName, out optionPtr); if (result != DhcpErrors.SUCCESS) { throw new DhcpServerException("DhcpGetOptionInfoV5", result); } try { var option = (DHCP_OPTION)Marshal.PtrToStructure(optionPtr, typeof(DHCP_OPTION)); return(DhcpServerOption.FromNative(Server, option, ClassName, VendorName)); } finally { Api.DhcpRpcFreeMemory(optionPtr); } }
private static DhcpServerOption GetOptionV0(DhcpServer Server, int OptionId) { IntPtr optionPtr; var result = Api.DhcpGetOptionInfo(Server.ipAddress.ToString(), OptionId, out optionPtr); if (result != DhcpErrors.SUCCESS) { throw new DhcpServerException("DhcpGetOptionInfo", result); } try { var option = (DHCP_OPTION)Marshal.PtrToStructure(optionPtr, typeof(DHCP_OPTION)); return(DhcpServerOption.FromNative(Server, option, null, null)); } finally { Api.DhcpRpcFreeMemory(optionPtr); } }