Interface Packet

All Superinterfaces:
Iterable<Packet>, Serializable
All Known Subinterfaces:
IpPacket, TransportPacket
All Known Implementing Classes:
AbstractPacket, AbstractPppPacket, ArpPacket, BsdLoopbackPacket, CompressedPacket, DnsPacket, Dot11ManagementPacket, Dot11ProbeRequestPacket, Dot11Selector, Dot1qVlanTagPacket, EncryptedPacket, EthernetPacket, FragmentedPacket, GtpSelector, GtpV1Packet, HdlcPppPacket, IcmpIdentifiablePacket, IcmpV4CommonPacket, IcmpV4DestinationUnreachablePacket, IcmpV4EchoPacket, IcmpV4EchoReplyPacket, IcmpV4InformationReplyPacket, IcmpV4InformationRequestPacket, IcmpV4InvokingPacketPacket, IcmpV4ParameterProblemPacket, IcmpV4RedirectPacket, IcmpV4SourceQuenchPacket, IcmpV4TimeExceededPacket, IcmpV4TimestampPacket, IcmpV4TimestampReplyPacket, IcmpV6CommonPacket, IcmpV6DestinationUnreachablePacket, IcmpV6EchoReplyPacket, IcmpV6EchoRequestPacket, IcmpV6HomeAgentAddressDiscoveryReplyPacket, IcmpV6HomeAgentAddressDiscoveryRequestPacket, IcmpV6InvokingPacketPacket, IcmpV6MobilePrefixAdvertisementPacket, IcmpV6MobilePrefixSolicitationPacket, IcmpV6NeighborAdvertisementPacket, IcmpV6NeighborSolicitationPacket, IcmpV6PacketTooBigPacket, IcmpV6ParameterProblemPacket, IcmpV6RedirectPacket, IcmpV6RouterAdvertisementPacket, IcmpV6RouterSolicitationPacket, IcmpV6TimeExceededPacket, IllegalPacket, IpSelector, IpV4Packet, IpV6ExtDestinationOptionsPacket, IpV6ExtFragmentPacket, IpV6ExtHopByHopOptionsPacket, IpV6ExtOptionsPacket, IpV6ExtRoutingPacket, IpV6ExtUnknownPacket, IpV6Packet, LinuxSllPacket, LlcPacket, PppPacket, PppSelector, RadiotapPacket, SctpPacket, SimplePacket, SnapPacket, Ssh2BinaryPacket, Ssh2DebugPacket, Ssh2DisconnectPacket, Ssh2IgnorePacket, Ssh2KexDhInitPacket, Ssh2KexDhReplyPacket, Ssh2KexInitPacket, Ssh2NewKeysPacket, Ssh2ServiceAcceptPacket, Ssh2ServiceRequestPacket, Ssh2UnimplementedPacket, Ssh2VersionExchangePacket, SshPacket, TcpPacket, UdpPacket, UnknownPacket

public interface Packet extends Iterable<Packet>, Serializable
The interface representing a packet which consists of a header and a payload. If you use
invalid reference
PropertiesBasedPacketFactory
, classes which implement this interface must implement the following method: public static Packet newPacket(byte[] rawData, int offset, int length) throws IllegalRawDataException
Since:
pcap4j 0.9.1
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    This interface is designed to be implemented by builder classes for packet objects.
    static interface 
    The interface representing a packet's header.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends Packet>
    boolean
    contains(Class<T> clazz)
    Returns true if this packet is or its payload includes an object of specified packet class; false otherwise.
    <T extends Packet>
    T
    get(Class<T> clazz)
    Traverses this packet and its payload to find an object of the specified packet class and returns the object.
    Returns a new Builder object populated with this object's fields' values.
    Returns the Header object representing this packet's header.
    getOuterOf(Class<? extends Packet> clazz)
    Returns the outer packet object of a packet object get(clazz) returns.
    Returns the Packet object representing this packet's payload.
    byte[]
    Returns this packet's raw data.
    int
    Returns the packet length in bytes.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • getHeader

      Packet.Header getHeader()
      Returns the Header object representing this packet's header.
      Returns:
      the Header object representing this packet's header. May be null if the header doesn't exist
    • getPayload

      Packet getPayload()
      Returns the Packet object representing this packet's payload.
      Returns:
      the Packet object representing this packet's payload. May be null if the payload doesn't exist
    • length

      int length()
      Returns the packet length in bytes.
      Returns:
      the length of the byte stream of the packet represented by this object in bytes
    • getRawData

      byte[] getRawData()
      Returns this packet's raw data.
      Returns:
      this packet's raw data, namely the byte stream which is actually sent through real network
    • get

      <T extends Packet> T get(Class<T> clazz)
      Traverses this packet and its payload to find an object of the specified packet class and returns the object. If there are more than one objects of the specified class in this object, this method returns the most outer one of them.
      Type Parameters:
      T - packet
      Parameters:
      clazz - the packet class of the object to get
      Returns:
      a packet object if found; otherwise null
    • getOuterOf

      Packet getOuterOf(Class<? extends Packet> clazz)
      Returns the outer packet object of a packet object get(clazz) returns.
      Parameters:
      clazz - the packet class of the object whose outer packet object is what you want to get
      Returns:
      a packet object if found; otherwise null
    • contains

      <T extends Packet> boolean contains(Class<T> clazz)
      Returns true if this packet is or its payload includes an object of specified packet class; false otherwise.
      Type Parameters:
      T - packet
      Parameters:
      clazz - the packet class of the object to search for
      Returns:
      true if this packet is or its payload includes an object of specified packet class; false otherwise
    • getBuilder

      Packet.Builder getBuilder()
      Returns a new Builder object populated with this object's fields' values.
      Returns:
      a new Builder object populated with this object's fields values