Ejemplo n.º 1
0
        public override IDHCPOption FromStream(Stream s)
        {
            DHCPOptionSubnetMask result = new DHCPOptionSubnetMask();

            if (s.Length != 4)
            {
                throw new IOException("Invalid DHCP option length");
            }
            result.m_SubnetMask = ParseHelper.ReadIPAddress(s);
            return(result);
        }
Ejemplo n.º 2
0
        public override IDHCPOption FromStream(Stream s)
        {
            DHCPOptionServerIdentifier result = new DHCPOptionServerIdentifier();

            if (s.Length != 4)
            {
                throw new IOException("Invalid DHCP option length");
            }
            result.m_IPAddress = ParseHelper.ReadIPAddress(s);
            return(result);
        }
Ejemplo n.º 3
0
        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;
            }
        }