using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Skyscraper.IO;

namespace skyscraper5.Ietf.Rfc826
{
    internal class ArpHeader
    {
        public ArpHeader(byte[] buffer)
        {
            MemoryStream ms = new MemoryStream(buffer);
            HardwareType = ms.ReadUInt16BE();
            ProtocolType = ms.ReadUInt16BE();
            HardwareLength = ms.ReadUInt8();
            ProtocolLength = ms.ReadUInt8();
            Operation = (OperationEnum)ms.ReadUInt16BE();
            SenderHardwareAddress = new PhysicalAddress(ms.ReadBytes(HardwareLength));
            SenderProtocolAddress = new IPAddress(ms.ReadBytes(ProtocolLength));
            TargetHardwareAddress = new PhysicalAddress(ms.ReadBytes(HardwareLength));
            TargetProtocolAddress = new IPAddress(ms.ReadBytes(ProtocolLength));
        }

        public IPAddress TargetProtocolAddress { get; set; }

        public PhysicalAddress TargetHardwareAddress { get; set; }

        public IPAddress SenderProtocolAddress { get; set; }

        public PhysicalAddress SenderHardwareAddress { get; set; }

        public byte ProtocolLength { get; set; }

        public byte HardwareLength { get; set; }

        public OperationEnum Operation { get; private set; }
        public enum OperationEnum : ushort
        {
            Request = 1,
            Reply = 2
        }
        public ushort HardwareType { get; set; }
        public ushort ProtocolType { get; private set; }

    }
}
