Esempio n. 1
0
 public static extern int DhcpSetOptionValue(
     string IpAddress,
     uint OptionID,
     ref DHCP_OPTION_SCOPE_INFO ScopeInfo,
     ref DHCP_OPTION_DATA OptionData);
Esempio n. 2
0
        private static DHCP_OPTION_DATA ConvertToNative(DhcpOption Option)
        {
            DHCP_OPTION_DATA_ELEMENT dataElement = new DHCP_OPTION_DATA_ELEMENT();
            DHCP_OPTION_DATA         data        = new DHCP_OPTION_DATA();
            IntPtr dataPtr;

            if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpStringDataOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpByteOption)
            {
                data.NumElements = Option.ByteData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.ByteData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordDWordOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpEncapsulatedDataOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption)
            {
                data.NumElements = Option.IntData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.IntData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType      = DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption;
                    dataElement.IpAddressOption = Option.IntData[i];
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpv6AddressOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpWordOption)
            {
                data.NumElements = Option.StringData.Length;
                data.Elements    = Marshal.AllocHGlobal(Option.StringData.Length);
                for (int i = 0; i < data.NumElements; i++)
                {
                    dataElement.OptionType       = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
                    dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
                    dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
                    Marshal.StructureToPtr(dataElement, dataPtr, false);
                }
                return(data);
            }
            return(data);
        }
Esempio n. 3
0
 public static extern int DhcpSetOptionValue(
     string IpAddress,
     uint OptionID,
     ref DHCP_OPTION_SCOPE_INFO ScopeInfo,
     ref DHCP_OPTION_DATA OptionData);
Esempio n. 4
0
 private static DHCP_OPTION_DATA ConvertToNative(DhcpOption Option)
 {
     DHCP_OPTION_DATA_ELEMENT dataElement = new DHCP_OPTION_DATA_ELEMENT();
     DHCP_OPTION_DATA data = new DHCP_OPTION_DATA();
     IntPtr dataPtr;
     if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpStringDataOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpByteOption) {
         data.NumElements = Option.ByteData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.ByteData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordDWordOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpDWordOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpEncapsulatedDataOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption) {
         data.NumElements = Option.IntData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.IntData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpIpAddressOption;
             dataElement.IpAddressOption = Option.IntData[i];
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpIpv6AddressOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     } else if (Option.OptionDataType == DHCP_OPTION_DATA_TYPE.DhcpWordOption) {
         data.NumElements = Option.StringData.Length;
         data.Elements = Marshal.AllocHGlobal(Option.StringData.Length);
         for (int i = 0; i < data.NumElements; i++) {
             dataElement.OptionType = DHCP_OPTION_DATA_TYPE.DhcpStringDataOption;
             dataElement.StringDataOption = Marshal.StringToBSTR(Option.StringData[i]);
             dataPtr = (IntPtr)(data.Elements.ToInt32()) + (i * Marshal.SizeOf(typeof(DHCP_OPTION_DATA_ELEMENT)));
             Marshal.StructureToPtr(dataElement, dataPtr, false);
         }
         return data;
     }
     return data;
 }