예제 #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
 /// <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
 /// <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
 /// <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
 /// <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);