public override IDHCPOption FromStream(Stream s) { DHCPOptionMaximumDHCPMessageSize result = new DHCPOptionMaximumDHCPMessageSize(); if (s.Length != 2) { throw new IOException("Invalid DHCP option length"); } result.m_MaxSize = ParseHelper.ReadUInt16(s); return(result); }
private DHCPMessage(Stream s) : this() { m_Opcode = (TOpcode)s.ReadByte(); m_HardwareType = (THardwareType)s.ReadByte(); m_ClientHardwareAddress = new byte[s.ReadByte()]; m_Hops = (byte)s.ReadByte(); m_XID = ParseHelper.ReadUInt32(s); m_Secs = ParseHelper.ReadUInt16(s); m_BroadCast = ((ParseHelper.ReadUInt16(s) & 0x8000) == 0x8000); m_ClientIPAddress = ParseHelper.ReadIPAddress(s); m_YourIPAddress = ParseHelper.ReadIPAddress(s); m_NextServerIPAddress = ParseHelper.ReadIPAddress(s); m_RelayAgentIPAddress = ParseHelper.ReadIPAddress(s); s.Read(m_ClientHardwareAddress, 0, m_ClientHardwareAddress.Length); for (int t = m_ClientHardwareAddress.Length; t < 16; t++) { s.ReadByte(); } byte[] serverHostNameBuffer = new byte[64]; s.Read(serverHostNameBuffer, 0, serverHostNameBuffer.Length); byte[] bootFileNameBuffer = new byte[128]; s.Read(bootFileNameBuffer, 0, bootFileNameBuffer.Length); // read options magic cookie if (s.ReadByte() != 99) { throw new IOException(); } if (s.ReadByte() != 130) { throw new IOException(); } if (s.ReadByte() != 83) { throw new IOException(); } if (s.ReadByte() != 99) { throw new IOException(); } byte[] optionsBuffer = new byte[s.Length - s.Position]; s.Read(optionsBuffer, 0, optionsBuffer.Length); byte overload = ScanOverload(new MemoryStream(optionsBuffer)); switch (overload) { default: m_ServerHostName = ParseHelper.ReadZString(new MemoryStream(serverHostNameBuffer)); m_BootFileName = ParseHelper.ReadZString(new MemoryStream(bootFileNameBuffer)); m_Options = ReadOptions(optionsBuffer, new byte[0], new byte[0]); break; case 1: m_ServerHostName = ParseHelper.ReadZString(new MemoryStream(serverHostNameBuffer)); m_Options = ReadOptions(optionsBuffer, bootFileNameBuffer, new byte[0]); break; case 2: m_BootFileName = ParseHelper.ReadZString(new MemoryStream(bootFileNameBuffer)); m_Options = ReadOptions(optionsBuffer, serverHostNameBuffer, new byte[0]); break; case 3: m_Options = ReadOptions(optionsBuffer, bootFileNameBuffer, serverHostNameBuffer); break; } }