Пример #1
0
        public DhcpTestPacket(
            string hexBytes,
            uint transactionId,
            DhcpOperation operation,
            ClientHardwareAddressType clientHardwareAddressType,
            byte[] clientHardwareAddressBytes,
            uint hops,
            uint secs,
            bool isBroadcast,
            IPAddress clientIp,
            IPAddress yourIp,
            IPAddress serverIp,
            IPAddress gatewayIp,
            string serverName,
            string bootFile,
            IReadOnlyList <IDhcpOption> options)
        {
            Bytes = hexBytes.AsHexBytes();

            TransactionId              = transactionId;
            Operation                  = operation;
            ClientHardwareAddressType  = clientHardwareAddressType;
            ClientHardwareAddressBytes = clientHardwareAddressBytes;
            Hops        = hops;
            Secs        = secs;
            IsBroadcast = isBroadcast;
            ClientIp    = clientIp;
            YourIp      = yourIp;
            ServerIp    = serverIp;
            GatewayIp   = gatewayIp;
            ServerName  = serverName;
            BootFile    = bootFile;
            Options     = options;
        }
Пример #2
0
 internal DhcpPacket(
     uint transactionId,
     DhcpOperation operation,
     ClientHardwareAddress clientHardwareAddress,
     uint hops,
     ushort secs,
     bool isBroadcast,
     IPAddress clientIp,
     IPAddress yourIp,
     IPAddress serverIp,
     IPAddress gatewayIp,
     string serverName,
     string bootFile,
     IReadOnlyList <IDhcpOption> options)
 {
     _options              = options;
     Secs                  = secs;
     IsBroadcast           = isBroadcast;
     ClientIp              = clientIp;
     YourIp                = yourIp;
     ServerIp              = serverIp;
     GatewayIp             = gatewayIp;
     ServerName            = serverName;
     BootFile              = bootFile;
     TransactionId         = transactionId;
     Operation             = operation;
     ClientHardwareAddress = clientHardwareAddress;
     Hops                  = hops;
 }
Пример #3
0
        public DhcpMessage(byte[] data)
        {
            var offset = 0;
            _mOperation = (DhcpOperation) data[offset++];
            _mHardware = (HardwareType) data[offset++];
            HardwareAddressLength = data[offset++];
            Hops = data[offset++];

            SessionId = BitConverter.ToInt32(data, offset);
            offset += 4;

            var secondsElapsed = new byte[2];
            Array.Copy(data, offset, secondsElapsed, 0, 2);
            SecondsElapsed = BitConverter.ToUInt16(ReverseByteOrder(secondsElapsed), 0);
            offset += 2;

            Flags = BitConverter.ToUInt16(data, offset);
            offset += 2;

            Array.Copy(data, offset, _mClientAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mAssignedAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mNextServerAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mRelayAgentAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, _mClientHardwareAddress, 0, 16);
            offset += 16;
            Array.Copy(data, offset, _mServerHostName, 0, 64);
            offset += 64;
            Array.Copy(data, offset, _mBootFileName, 0, 128);
            offset += 128;
            //Array.Copy(data, offset, this.m_VendorSpecificInformation, 0, 64);
            //offset += 64;
            //offset += 192; // Skip server host name and boot file

            if (offset + 4 < data.Length &&
                (BitConverter.ToUInt32(data, offset) == DhcpOptionsMagicNumber ||
                 BitConverter.ToUInt32(data, offset) == WinDhcpOptionsMagicNumber))
            {
                offset += 4;
                var end = false;

                while (!end && offset < data.Length)
                {
                    var option = (DhcpOption) data[offset];
                    offset++;

                    int optionLen;

                    switch (option)
                    {
                        case DhcpOption.Pad:
                            continue;
                        case DhcpOption.End:
                            end = true;
                            continue;
                        default:
                            optionLen = data[offset];
                            offset++;
                            break;
                    }

                    var optionData = new byte[optionLen];

                    Array.Copy(data, offset, optionData, 0, optionLen);
                    offset += optionLen;

                    _mOptions.Add(option, optionData);
                    _mOptionDataSize += optionLen;
                }
            }
        }
Пример #4
0
        internal DhcpPacketBuilder WithOperation(DhcpOperation operation)
        {
            _operation = operation;

            return(this);
        }
Пример #5
0
        public DhcpMessage(Byte[] data)
        {
            Int32 offset = 0;
            this.m_Operation = (DhcpOperation)data[offset++];
            this.m_Hardware = (HardwareType)data[offset++];
            this.m_HardwareAddressLength = data[offset++];
            this.m_Hops = data[offset++];

            this.m_SessionId = BitConverter.ToInt32(data, offset);
            offset += 4;

            Byte[] secondsElapsed = new Byte[2];
            Array.Copy(data, offset, secondsElapsed, 0, 2);
            this.m_SecondsElapsed = BitConverter.ToUInt16(ReverseByteOrder(secondsElapsed), 0);
            offset += 2;

            this.m_Flags = BitConverter.ToUInt16(data, offset);
            offset += 2;

            Array.Copy(data, offset, this.m_ClientAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_AssignedAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_NextServerAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_RelayAgentAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_ClientHardwareAddress, 0, 16);
            offset += 16;

            offset += 192; // Skip server host name and boot file

            if (offset + 4 < data.Length &&
                (BitConverter.ToUInt32(data, offset) == DhcpOptionsMagicNumber || BitConverter.ToUInt32(data, offset) == WinDhcpOptionsMagicNumber))
            {
                offset += 4;
                Boolean end = false;

                while (!end && offset < data.Length)
                {
                    DhcpOption option = (DhcpOption)data[offset];
                    offset++;

                    Int32 optionLen;

                    switch (option)
                    {
                        case DhcpOption.Pad:
                            continue;
                        case DhcpOption.End:
                            end = true;
                            continue;
                        default:
                            optionLen = (Int32)data[offset];
                            offset++;
                            break;
                    }

                    Byte[] optionData = new Byte[optionLen];

                    Array.Copy(data, offset, optionData, 0, optionLen);
                    offset += optionLen;

                    this.m_Options.Add(option, optionData);
                    this.m_OptionDataSize += optionLen;
                }
            }
        }
Пример #6
0
        public DhcpMessage(Byte[] data)
        {
            Int32 offset = 0;

            this.m_Operation             = (DhcpOperation)data[offset++];
            this.m_Hardware              = (HardwareType)data[offset++];
            this.m_HardwareAddressLength = data[offset++];
            this.m_Hops = data[offset++];

            this.m_SessionId = BitConverter.ToInt32(data, offset);
            offset          += 4;

            Byte[] secondsElapsed = new Byte[2];
            Array.Copy(data, offset, secondsElapsed, 0, 2);
            this.m_SecondsElapsed = BitConverter.ToUInt16(ReverseByteOrder(secondsElapsed), 0);
            offset += 2;

            this.m_Flags = BitConverter.ToUInt16(data, offset);
            offset      += 2;

            Array.Copy(data, offset, this.m_ClientAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_AssignedAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_NextServerAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_RelayAgentAddress, 0, 4);
            offset += 4;
            Array.Copy(data, offset, this.m_ClientHardwareAddress, 0, 16);
            offset += 16;

            offset += 192; // Skip server host name and boot file

            if (offset + 4 < data.Length &&
                (BitConverter.ToUInt32(data, offset) == DhcpOptionsMagicNumber || BitConverter.ToUInt32(data, offset) == WinDhcpOptionsMagicNumber))
            {
                offset += 4;
                Boolean end = false;

                while (!end && offset < data.Length)
                {
                    DhcpOption option = (DhcpOption)data[offset];
                    offset++;

                    Int32 optionLen;

                    switch (option)
                    {
                    case DhcpOption.Pad:
                        continue;

                    case DhcpOption.End:
                        end = true;
                        continue;

                    default:
                        optionLen = (Int32)data[offset];
                        offset++;
                        break;
                    }

                    Byte[] optionData = new Byte[optionLen];

                    Array.Copy(data, offset, optionData, 0, optionLen);
                    offset += optionLen;

                    this.m_Options.Add(option, optionData);
                    this.m_OptionDataSize += optionLen;
                }
            }
        }