示例#1
0
        static void SendAppleBootList(DHCPRequest dhcpRequest)
        {
            Trace.WriteLine("Request Is An Apple NetBoot");
            int bsdpPort = 68;
            var vendorSpecificInformation = OptionData.GetOptionData(DHCPOption.VendorSpecificInformation, dhcpRequest.requestData);
            var strVendorInformation      = Utility.ByteArrayToString(vendorSpecificInformation, true);

            if (strVendorInformation.Length >= 21)
            {
                var isReturnPort = strVendorInformation.Substring(14, 4);
                if (isReturnPort == "0502")
                {
                    var returnPort = strVendorInformation.Substring(18, 4);
                    bsdpPort = Convert.ToInt32(returnPort, 16);
                }
            }

            var replyOptions = new DHCPReplyOptions();

            replyOptions.OtherOptions.Add(DHCPOption.Vendorclassidentifier, Settings.AAPLBSDPC);
            replyOptions.OtherOptions.Add(DHCPOption.VendorSpecificInformation, Utility.StringToByteArray(Settings.VendorInfo));
            var reply = new DHCPReply(dhcpRequest);

            reply.Send(DHCPMsgType.DHCPACK, replyOptions, bsdpPort);
        }
示例#2
0
        private byte[] CreateOptionStruct(DHCPMsgType msgType, DHCPReplyOptions replyOptions)
        {
            byte[] resultOptions = null;

            // Option82?
            var relayInfo = OptionData.GetOptionData(DHCPOption.RelayInfo, _dhcpRequest.requestData);

            CreateOptionElement(ref resultOptions, DHCPOption.DHCPMessageTYPE, new [] { (byte)msgType });
            // Server identifier - our IP address
            if (_dhcpRequest.dhcpServer.ServerIdentifier != null)
            {
                CreateOptionElement(ref resultOptions, DHCPOption.ServerIdentifier, _dhcpRequest.dhcpServer.ServerIdentifier.GetAddressBytes());
            }

            // Requested options
            if (replyOptions != null)
            {
                foreach (var option in replyOptions.OtherOptions.Keys)
                {
                    CreateOptionElement(ref resultOptions, option, replyOptions.OtherOptions[option]);
                }
            }

            // Option 82? Send it back!
            if (relayInfo != null)
            {
                CreateOptionElement(ref resultOptions, DHCPOption.RelayInfo, relayInfo);
            }

            // Create the end option
            Array.Resize(ref resultOptions, resultOptions.Length + 1);
            Array.Copy(new byte[] { 255 }, 0, resultOptions, resultOptions.Length - 1, 1);
            return(resultOptions);
        }
        /// <summary>
        /// Returns relay info (option 82)
        /// </summary>
        /// <returns>Relay info</returns>
        public RelayInfo?GetRelayInfo()
        {
            var result    = new RelayInfo();
            var relayInfo = OptionData.GetOptionData(DHCPOption.RelayInfo, requestData);

            if (relayInfo != null)
            {
                int i = 0;
                while (i < relayInfo.Length)
                {
                    var subOptID = relayInfo[i];
                    if (subOptID == 1)
                    {
                        result.AgentCircuitID = new byte[relayInfo[i + 1]];
                        Array.Copy(relayInfo, i + 2, result.AgentCircuitID, 0, relayInfo[i + 1]);
                    }
                    else if (subOptID == 2)
                    {
                        result.AgentRemoteID = new byte[relayInfo[i + 1]];
                        Array.Copy(relayInfo, i + 2, result.AgentRemoteID, 0, relayInfo[i + 1]);
                    }
                    i += 2 + relayInfo[i + 1];
                }
                return(result);
            }
            return(null);
        }
 public ClientSystemArch GetClientSystemArch()
 {
     byte[] DData;
     DData = OptionData.GetOptionData(DHCPOption.ClientSystemArchitecture, requestData);
     if (DData != null)
     {
         return((ClientSystemArch)DData[1]);
     }
     return(ClientSystemArch.Error);
 }
 /// <summary>
 /// Returns type of DHCP request
 /// </summary>
 /// <returns>DHCP message type</returns>
 public DHCPMsgType GetMsgType()
 {
     byte[] DData;
     DData = OptionData.GetOptionData(DHCPOption.DHCPMessageTYPE, requestData);
     if (DData != null)
     {
         return((DHCPMsgType)DData[0]);
     }
     return(0);
 }
        /// <summary>
        /// Returns requested IP (option 50)
        /// </summary>
        /// <returns>Requested IP</returns>
        public IPAddress GetRequestedIP()
        {
            var ipBytes = OptionData.GetOptionData(DHCPOption.RequestedIPAddress, requestData);

            if (ipBytes == null)
            {
                return(null);
            }
            return(new IPAddress(ipBytes));
        }
        /// <summary>
        /// Returns array of requested by client options
        /// </summary>
        /// <returns>Array of requested by client options</returns>
        public DHCPOption[] GetRequestedOptionsList()
        {
            var reqList = OptionData.GetOptionData(DHCPOption.ParameterRequestList, requestData);
            var optList = new List <DHCPOption>();

            if (reqList != null)
            {
                foreach (var option in reqList)
                {
                    optList.Add((DHCPOption)option);
                }
            }
            else
            {
                return(null);
            }
            return(optList.ToArray());
        }
 public byte[] GetVendorSpecificInformation()
 {
     return(OptionData.GetOptionData(DHCPOption.VendorSpecificInformation, requestData));
 }
 public byte[] GetVendorOptionData()
 {
     return(OptionData.GetOptionData(DHCPOption.Vendorclassidentifier, requestData));
 }