Beispiel #1
0
        private static byte[] BuildDataStructure(DHCPMessage.Packet packet)
        {
            byte[] mArray;

            try
            {
                mArray = new byte[0];
                AddOptionElement(new [] { packet.op }, ref mArray);
                AddOptionElement(new [] { packet.htype }, ref mArray);
                AddOptionElement(new [] { packet.hlen }, ref mArray);
                AddOptionElement(new [] { packet.hops }, ref mArray);
                AddOptionElement(packet.xid, ref mArray);
                AddOptionElement(packet.secs, ref mArray);
                AddOptionElement(packet.flags, ref mArray);
                AddOptionElement(packet.ciaddr, ref mArray);
                AddOptionElement(packet.yiaddr, ref mArray);
                AddOptionElement(packet.siaddr, ref mArray);
                AddOptionElement(packet.giaddr, ref mArray);
                AddOptionElement(packet.chaddr, ref mArray);
                AddOptionElement(packet.sname, ref mArray);
                AddOptionElement(packet.file, ref mArray);

                AddOptionElement(packet.mcookie, ref mArray);
                AddOptionElement(packet.options, ref mArray);
                return(mArray);
            }
            finally
            {
                mArray = null;
            }
        }
        /// <summary>
        /// Returns option content
        /// </summary>
        /// <param name="option">Option to retrieve</param>
        /// <param name="requestData">requested Data</param>
        /// <returns>Option content</returns>
        public static byte[] GetOptionData(DHCPOption option, DHCPMessage.Packet requestData)
        {
            int  DHCPId = 0;
            byte DDataID, DataLength = 0;

            byte[] dumpData;

            DHCPId = (int)option;
            for (int i = 0; i < requestData.options.Length; i++)
            {
                DDataID = requestData.options[i];
                if (DDataID == (byte)DHCPOption.END_Option)
                {
                    break;
                }
                if (DDataID == DHCPId)
                {
                    DataLength = requestData.options[i + 1];
                    dumpData   = new byte[DataLength];
                    Array.Copy(requestData.options, i + 2, dumpData, 0, DataLength);
                    return(dumpData);
                }
                else
                {
                    DataLength = requestData.options[i + 1];
                    i         += 1 + DataLength;
                }
            }

            return(null);
        }