public DHCPMessage() { _HardwareType = EHardwareType.Ethernet_10Mb; _ClientIPAddress = IPAddress.Any; _YourIPAddress = IPAddress.Any; _NextServerIPAddress = IPAddress.Any; _RelayAgentIPAddress = IPAddress.Any; // _Options = new List<IDHCPOption>(); }
public Hardware(float _weight, EHardwareType _type, Warranty _warranty, float _width, float _height, float _length, int _id, string _productName, string _description, double _priceExclBTW) : base(_id, _productName, _description, _priceExclBTW) { Weight = _weight; Type = _type; Warranty = _warranty; Width = _width; Height = _height; Length = _length; }
public DHCPOptionClientIdentifier61(EHardwareType hardwareType, byte[] otherData) : base(EDHCPOption.Client_Identifier) { _HardwareType = hardwareType; _OtherData = otherData; }
public DHCPOptionClientIdentifier61() : base(EDHCPOption.Client_Identifier) { _HardwareType = EHardwareType.Unknown; _OtherData = new byte[0]; }
private DHCPMessage(Stream stream) : this() { _Opcode = (EOpcode)stream.ReadByte(); _HardwareType = (EHardwareType)stream.ReadByte(); // Đọc phần Hlen (HardwareLength) để xác định độ dài mảng lưu ClientHardwareAddress _ClientHardwareAddress = new byte[stream.ReadByte()]; _Hops = (byte)stream.ReadByte(); _XID = Utilities.ReadWriteStream.Read4Bytes(stream); _Secs = Utilities.ReadWriteStream.Read2Bytes(stream); // Ref: [RFC2131] page 11 // Flag 16 bit, chỉ có bit 0 là đang được dùng (to specify server MUST send broadcast to client or not) _Flags_Broadcast = ((Utilities.ReadWriteStream.Read2Bytes(stream) & 0x8000) == 0x8000); _ClientIPAddress = Utilities.ReadWriteStream.ReadIPAddress(stream); _YourIPAddress = Utilities.ReadWriteStream.ReadIPAddress(stream); _NextServerIPAddress = Utilities.ReadWriteStream.ReadIPAddress(stream); _RelayAgentIPAddress = Utilities.ReadWriteStream.ReadIPAddress(stream); // ClientHardwareAddress được pad cho đủ 16 bytes, sau khi đọc ClientHardwareAddress cần đọc tiếp phần còn lạiđể loại bỏ bytes padding stream.Read(_ClientHardwareAddress, 0, _ClientHardwareAddress.Length); for (int i = _ClientHardwareAddress.Length; i < 16; i++) { stream.ReadByte(); } // Ref: [RFC2132] Section 9.3, page 26 // ServerHostname (sname) và BootFileName (file) có thể được overload để lưu DHCPOption. // Chuyển thành mảng byte buffer để xử lí sau byte[] serverHostnameBuffer = new byte[64]; byte[] bootFileNameBuffer = new byte[128]; stream.Read(serverHostnameBuffer, 0, serverHostnameBuffer.Length); stream.Read(bootFileNameBuffer, 0, bootFileNameBuffer.Length); // Ref: [RFC1048], [https://community.cisco.com/t5/switching/why-dhcp-option-has-quot-magic-cookie-quot/td-p/1764244] // Ban đầu // Vì DHCP message có format gần như giống hoàn toàn với BOOTP message. // Nên magic cookie dùng để phân biệt DHCP message với BOOTP. // Nếu như tồn tại magic cookie, thì mọi thứ phía sau đó được xử lí như DHCP Options. // Bây giờ // magic cookie được gán cố định theo RFC1048 và các RFC sau chấp nhận nó, nên đây xem như trường hiển nhiên // nếu như không có giá trị như được đề cập ở dưới, thì đã có lỗi trong quá trình IO hoặc truyền // Magic cookies được cố định là 4 bytes [0x63 0x82 0x53 0x63] hay [99 130 83 99] if (stream.ReadByte() != 0x63) { throw new IOException(); } if (stream.ReadByte() != 0x82) { throw new IOException(); } if (stream.ReadByte() != 0x53) { throw new IOException(); } if (stream.ReadByte() != 0x63) { throw new IOException(); } // Phần còn lại là DHCPOption. Phần này cần xử lí byte[] optionsBuffer = new byte[stream.Length - stream.Position]; stream.Read(optionsBuffer, 0, optionsBuffer.Length); // Xác định thông tin trong DHCPOptionOverload byte overload = ScanOverload(new MemoryStream(optionsBuffer)); switch (overload) { default: _ServerHostname = Utilities.ReadWriteStream.ReadStringToNull(new MemoryStream(serverHostnameBuffer)); _BootFileName = Utilities.ReadWriteStream.ReadStringToNull(new MemoryStream(bootFileNameBuffer)); _Options = ReadOptions(optionsBuffer, new byte[0], new byte[0]); break; case 1: _ServerHostname = Utilities.ReadWriteStream.ReadStringToNull(new MemoryStream(serverHostnameBuffer)); _Options = ReadOptions(optionsBuffer, bootFileNameBuffer, new byte[0]); break; case 2: _BootFileName = Utilities.ReadWriteStream.ReadStringToNull(new MemoryStream(bootFileNameBuffer)); _Options = ReadOptions(optionsBuffer, serverHostnameBuffer, new byte[0]); break; case 3: _Options = ReadOptions(optionsBuffer, bootFileNameBuffer, serverHostnameBuffer); break; } }