コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId from the Default options
 /// </summary>
 /// <param name="optionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="IDhcpServerOption"/>.</returns>
 public IDhcpServerOption GetDefaultOption(DhcpServerOptionIds optionId)
 => DhcpServerOption.GetDefaultOption(Server, (int)optionId);
コード例 #6
0
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId from the Default options
 /// </summary>
 /// <param name="optionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="IDhcpServerOption"/>.</returns>
 public IDhcpServerOption GetDefaultOption(int optionId)
 => DhcpServerOption.GetDefaultOption(Server, optionId);
コード例 #7
0
 public IEnumerable <IDhcpServerOption> GetVendorOptions(string vendorName)
 => DhcpServerOption.EnumVendorOptions(Server, vendorName);
コード例 #8
0
 public IEnumerable <IDhcpServerOption> GetUserOptions(string className)
 => DhcpServerOption.EnumUserOptions(Server, className);
コード例 #9
0
ファイル: DhcpServer.cs プロジェクト: yanzj/DhcpServerApi
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId from the Default options
 /// </summary>
 /// <param name="OptionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="DhcpServerOption"/>.</returns>
 public DhcpServerOption GetOption(int OptionId)
 {
     return(DhcpServerOption.GetDefaultOption(this, OptionId));
 }
コード例 #10
0
 private DhcpServerOption GetOption()
 {
     return(DhcpServerOption.GetOption(this.Server, this.OptionId, this.ClassName, this.VendorName));
 }
コード例 #11
0
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId within a Vendor Class
 /// </summary>
 /// <param name="vendorName">The name of the Vendor Class to retrieve the Option from</param>
 /// <param name="optionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="IDhcpServerOption"/>.</returns>
 public IDhcpServerOption GetVendorOption(string vendorName, int optionId)
 => DhcpServerOption.GetVendorOption(Server, vendorName, optionId);
コード例 #12
0
ファイル: DhcpServer.cs プロジェクト: yanzj/DhcpServerApi
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId Value from the Default options
 /// </summary>
 /// <param name="Option">The associated option to retrieve the option value for</param>
 /// <returns>A <see cref="DhcpServerOptionValue"/>.</returns>
 public DhcpServerOptionValue GetOptionValue(DhcpServerOption Option)
 {
     return(Option.GetGlobalValue());
 }
コード例 #13
0
ファイル: DhcpServer.cs プロジェクト: yanzj/DhcpServerApi
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId within a User Class
 /// </summary>
 /// <param name="ClassName">The name of the User Class to retrieve the Option from</param>
 /// <param name="OptionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="DhcpServerOption"/>.</returns>
 public DhcpServerOption GetUserOption(string ClassName, int OptionId)
 {
     return(DhcpServerOption.GetUserOption(this, OptionId, ClassName));
 }
コード例 #14
0
ファイル: DhcpServer.cs プロジェクト: yanzj/DhcpServerApi
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId within a Vendor Class
 /// </summary>
 /// <param name="VendorName">The name of the Vendor Class to retrieve the Option from</param>
 /// <param name="OptionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="DhcpServerOption"/>.</returns>
 public DhcpServerOption GetVendorOption(string VendorName, int OptionId)
 {
     return(DhcpServerOption.GetVendorOption(this, OptionId, VendorName));
 }
コード例 #15
0
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId within a User Class
 /// </summary>
 /// <param name="className">The name of the User Class to retrieve the Option from</param>
 /// <param name="optionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="IDhcpServerOption"/>.</returns>
 public IDhcpServerOption GetUserOption(string className, int optionId)
 => DhcpServerOption.GetUserOption(Server, className, optionId);
コード例 #16
0
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId within a User Class
 /// </summary>
 /// <param name="className">The name of the User Class to retrieve the Option from</param>
 /// <param name="optionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="IDhcpServerOption"/>.</returns>
 public IDhcpServerOption GetUserOption(string className, DhcpServerOptionIds optionId)
 => DhcpServerOption.GetUserOption(Server, className, (int)optionId);
コード例 #17
0
 public IEnumerator <IDhcpServerOption> GetEnumerator()
 => DhcpServerOption.GetAllOptions(Server).GetEnumerator();
コード例 #18
0
 /// <summary>
 /// Queries the DHCP Server for the specified OptionId within a Vendor Class
 /// </summary>
 /// <param name="vendorName">The name of the Vendor Class to retrieve the Option from</param>
 /// <param name="optionId">The identifier for the option to retrieve</param>
 /// <returns>A <see cref="IDhcpServerOption"/>.</returns>
 public IDhcpServerOption GetVendorOption(string vendorName, DhcpServerOptionIds optionId)
 => DhcpServerOption.GetVendorOption(Server, vendorName, (int)optionId);
コード例 #19
0
 public IEnumerable <IDhcpServerOption> GetDefaultOptions()
 => DhcpServerOption.EnumDefaultOptions(Server);
コード例 #20
0
 /// <summary>
 /// Retrieves the Option Value assoicated with the Option and Scope
 /// </summary>
 /// <param name="Option">The associated option to retrieve the option value for</param>
 /// <returns>A <see cref="DhcpServerOptionValue"/>.</returns>
 public DhcpServerOptionValue GetOptionValue(DhcpServerOption Option)
 {
     return(Option.GetScopeValue(this));
 }
コード例 #21
0
 private DhcpServerOption GetOption() => DhcpServerOption.GetOption(Server, OptionId, ClassName, VendorName);