Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
Ejemplo n.º 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);
Ejemplo n.º 7
0
 public IEnumerable <IDhcpServerOption> GetVendorOptions(string vendorName)
 => DhcpServerOption.EnumVendorOptions(Server, vendorName);
Ejemplo n.º 8
0
 public IEnumerable <IDhcpServerOption> GetUserOptions(string className)
 => DhcpServerOption.EnumUserOptions(Server, className);
Ejemplo n.º 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));
 }
Ejemplo n.º 10
0
 private DhcpServerOption GetOption()
 {
     return(DhcpServerOption.GetOption(this.Server, this.OptionId, this.ClassName, this.VendorName));
 }
Ejemplo n.º 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);
Ejemplo n.º 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());
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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);
Ejemplo n.º 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);
Ejemplo n.º 17
0
 public IEnumerator <IDhcpServerOption> GetEnumerator()
 => DhcpServerOption.GetAllOptions(Server).GetEnumerator();
Ejemplo n.º 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);
Ejemplo n.º 19
0
 public IEnumerable <IDhcpServerOption> GetDefaultOptions()
 => DhcpServerOption.EnumDefaultOptions(Server);
Ejemplo n.º 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));
 }
Ejemplo n.º 21
0
 private DhcpServerOption GetOption() => DhcpServerOption.GetOption(Server, OptionId, ClassName, VendorName);