IPPacket

open class IPPacket

The class to process and build IP packet.

Note

Only IPv4 is supported as of now.
  • Get the version of the IP Packet without parsing the whole packet.

    Declaration

    Swift

    open static func peekIPVersion(_ data: Data) -> IPVersion?

    Parameters

    data

    The data containing the whole IP packet.

    Return Value

    The version of the packet. Returns nil if failed to parse the packet.

  • Get the protocol of the IP Packet without parsing the whole packet.

    Declaration

    Swift

    open static func peekProtocol(_ data: Data) -> TransportProtocol?

    Parameters

    data

    The data containing the whole IP packet.

    Return Value

    The protocol of the packet. Returns nil if failed to parse the packet.

  • Get the source IP address of the IP packet without parsing the whole packet.

    Declaration

    Swift

    open static func peekSourceAddress(_ data: Data) -> IPAddress?

    Parameters

    data

    The data containing the whole IP packet.

    Return Value

    The source IP address of the packet. Returns nil if failed to parse the packet.

  • Get the destination IP address of the IP packet without parsing the whole packet.

    Declaration

    Swift

    open static func peekDestinationAddress(_ data: Data) -> IPAddress?

    Parameters

    data

    The data containing the whole IP packet.

    Return Value

    The destination IP address of the packet. Returns nil if failed to parse the packet.

  • Get the source port of the IP packet without parsing the whole packet.

    Note

    Only TCP and UDP packet has port field.

    Declaration

    Swift

    open static func peekSourcePort(_ data: Data) -> Port?

    Parameters

    data

    The data containing the whole IP packet.

    Return Value

    The source IP address of the packet. Returns nil if failed to parse the packet.

  • Get the destination port of the IP packet without parsing the whole packet.

    Note

    Only TCP and UDP packet has port field.

    Declaration

    Swift

    open static func peekDestinationPort(_ data: Data) -> Port?

    Parameters

    data

    The data containing the whole IP packet.

    Return Value

    The destination IP address of the packet. Returns nil if failed to parse the packet.

  • The version of the current IP packet.

    Declaration

    Swift

    open var version: IPVersion = .iPv4
  • The length of the IP packet header.

    Declaration

    Swift

    open var headerLength: UInt8 = 20
  • tos

    This contains the DSCP and ECN of the IP packet.

    Note

    Since we can not send custom IP packet out with NetworkExtension, this is useless and simply ignored.

    Declaration

    Swift

    open var tos: UInt8 = 0
  • This should be the length of the datagram. This value is not read from header since NEPacketTunnelFlow has already taken care of it for us.

    Declaration

    Swift

    open var totalLength: UInt16
  • Identification of the current packet.

    Note

    Since we do not support fragment, this is ignored and always will be zero.

    Note

    Theoratically, this should be a sequentially increasing number. It probably will be implemented.

    Declaration

    Swift

    var identification: UInt16 = 0
  • Offset of the current packet.

    Note

    Since we do not support fragment, this is ignored and always will be zero.

    Declaration

    Swift

    var offset: UInt16 = 0
  • TTL

    TTL of the packet.

    Declaration

    Swift

    var TTL: UInt8 = 64
  • Source IP address.

    Declaration

    Swift

    var sourceAddress: IPAddress!
  • Destination IP address.

    Declaration

    Swift

    var destinationAddress: IPAddress!
  • Transport protocol of the packet.

    Declaration

    Swift

    var transportProtocol: TransportProtocol!
  • Parser to parse the payload in IP packet.

    Declaration

    Swift

    var protocolParser: TransportProtocolParserProtocol!
  • The data representing the packet.

    Declaration

    Swift

    var packetData: Data!
  • Initailize a new instance to build IP packet.

    Declaration

    Swift

    init()
  • Initailize an IPPacket with data.

    Declaration

    Swift

    init?(packetData: Data)

    Parameters

    packetData

    The data containing a whole packet.

  • Undocumented

    Declaration

    Swift

    open class IPPacket
  • Undocumented

    Declaration

    Swift

    open class IPPacket
  • Undocumented

    Declaration

    Swift

    open class IPPacket
  • Undocumented

    Declaration

    Swift

    open class IPPacket
  • Undocumented

    Declaration

    Swift

    open class IPPacket
  • Undocumented

    Declaration

    Swift

    open class IPPacket
  • Undocumented

    Declaration

    Swift

    open class IPPacket