Class ARP

  • All Implemented Interfaces:
    IPacket

    public class ARP
    extends BasePacket
    Representation of an ARP Packet.
    • Field Detail

      • hardwareType

        protected short hardwareType
      • protocolType

        protected short protocolType
      • hardwareAddressLength

        protected byte hardwareAddressLength
      • protocolAddressLength

        protected byte protocolAddressLength
      • opCode

        protected short opCode
      • senderHardwareAddress

        protected byte[] senderHardwareAddress
      • senderProtocolAddress

        protected byte[] senderProtocolAddress
      • targetHardwareAddress

        protected byte[] targetHardwareAddress
      • targetProtocolAddress

        protected byte[] targetProtocolAddress
    • Constructor Detail

      • ARP

        public ARP()
    • Method Detail

      • getHardwareType

        public short getHardwareType()
        Returns:
        the hardwareType
      • setHardwareType

        public ARP setHardwareType​(short hwType)
        Parameters:
        hwType - the hardwareType to set
        Returns:
        this
      • getProtocolType

        public short getProtocolType()
        Returns:
        the protocolType
      • setProtocolType

        public ARP setProtocolType​(short protoType)
        Parameters:
        protoType - the protocolType to set
        Returns:
        this
      • getHardwareAddressLength

        public byte getHardwareAddressLength()
        Returns:
        the hardwareAddressLength
      • setHardwareAddressLength

        public ARP setHardwareAddressLength​(byte hwAddressLength)
        Parameters:
        hwAddressLength - the hardwareAddressLength to set
        Returns:
        this
      • getProtocolAddressLength

        public byte getProtocolAddressLength()
        Returns:
        the protocolAddressLength
      • setProtocolAddressLength

        public ARP setProtocolAddressLength​(byte protoAddressLength)
        Parameters:
        protoAddressLength - the protocolAddressLength to set
        Returns:
        this
      • getOpCode

        public short getOpCode()
        Returns:
        the opCode
      • setOpCode

        public ARP setOpCode​(short op)
        Parameters:
        op - the opCode to set
        Returns:
        this
      • getSenderHardwareAddress

        public byte[] getSenderHardwareAddress()
        Returns:
        the senderHardwareAddress
      • setSenderHardwareAddress

        public ARP setSenderHardwareAddress​(byte[] senderHWAddress)
        Parameters:
        senderHWAddress - the senderHardwareAddress to set
        Returns:
        this
      • getSenderProtocolAddress

        public byte[] getSenderProtocolAddress()
        Returns:
        the senderProtocolAddress
      • setSenderProtocolAddress

        public ARP setSenderProtocolAddress​(byte[] senderProtoAddress)
        Parameters:
        senderProtoAddress - the senderProtocolAddress to set
        Returns:
        this
      • setSenderProtocolAddress

        public ARP setSenderProtocolAddress​(int address)
      • getTargetHardwareAddress

        public byte[] getTargetHardwareAddress()
        Returns:
        the targetHardwareAddress
      • setTargetHardwareAddress

        public ARP setTargetHardwareAddress​(byte[] targetHWAddress)
        Parameters:
        targetHWAddress - the targetHardwareAddress to set
        Returns:
        this
      • getTargetProtocolAddress

        public byte[] getTargetProtocolAddress()
        Returns:
        the targetProtocolAddress
      • isGratuitous

        public boolean isGratuitous()
        Returns:
        True if gratuitous ARP (SPA = TPA), false otherwise
      • setTargetProtocolAddress

        public ARP setTargetProtocolAddress​(byte[] targetProtoAddress)
        Parameters:
        targetProtoAddress - the targetProtocolAddress to set
        Returns:
        this
      • setTargetProtocolAddress

        public ARP setTargetProtocolAddress​(int address)
      • serialize

        public byte[] serialize()
        Description copied from interface: IPacket
        Sets all payloads parent packet if applicable, then serializes this packet and all payloads.
        Returns:
        a byte[] containing this packet and payloads
      • buildArpRequest

        public static Ethernet buildArpRequest​(byte[] senderMacAddress,
                                               byte[] senderIpAddress,
                                               byte[] targetMacAddress,
                                               byte[] targetIpAddress,
                                               byte[] destinationMacAddress,
                                               short vlanId)
        Builds an ARP request using the supplied parameters.
        Parameters:
        senderMacAddress - the mac address of the sender
        senderIpAddress - the ip address of the sender
        targetMacAddress - the mac address of the target
        targetIpAddress - the ip address to resolve
        destinationMacAddress - the mac address put in Ethernet header
        vlanId - the vlan id
        Returns:
        the Ethernet frame containing the ARP request
      • buildArpRequest

        public static Ethernet buildArpRequest​(byte[] senderMacAddress,
                                               byte[] senderIpAddress,
                                               byte[] targetIpAddress,
                                               short vlanId)
        Builds an ARP request using the supplied parameters.
        Parameters:
        senderMacAddress - the mac address of the sender
        senderIpAddress - the ip address of the sender
        targetIpAddress - the ip address to resolve
        vlanId - the vlan id
        Returns:
        the Ethernet frame containing the ARP request
      • buildArpReply

        public static Ethernet buildArpReply​(Ip4Address srcIp,
                                             MacAddress srcMac,
                                             Ethernet request)
        Builds an ARP reply based on a request.
        Parameters:
        srcIp - the IP address to use as the reply source
        srcMac - the MAC address to use as the reply source
        request - the ARP request we got
        Returns:
        an Ethernet frame containing the ARP reply
      • deserializer

        public static Deserializer<ARP> deserializer()
        Deserializer function for ARP packets.
        Returns:
        deserializer function
      • duplicate

        public ARP duplicate()
        Make an exact copy of the ARP packet.
        Returns:
        copy of the packet