Frame Header *¶
pcapkit.protocols.pcap.frame contains
Frame only,
which implements extractor for frame headers of PCAP,
whose structure is described as below:
typedef struct pcaprec_hdr_s {
guint32 ts_sec; /* timestamp seconds */
guint32 ts_usec; /* timestamp microseconds */
guint32 incl_len; /* number of octets of packet saved in file */
guint32 orig_len; /* actual length of packet */
} pcaprec_hdr_t;
-
class
pcapkit.protocols.pcap.frame.Frame(file=None, length=None, **kwargs)[source]¶ Bases:
pcapkit.protocols.protocol.ProtocolPer packet frame header extractor.
-
__proto__: DefaultDict[int, Tuple[str, str]]¶ Protocol index mapping for decoding next layer, c.f.
self._decode_next_layer&self._import_next_layer. The values should be a tuple representing the module name and class name.Code
Module
Class
1
228
pcapkit.protocols.link.internet.ipv4IPv4229
pcapkit.protocols.link.internet.ipv6IPv6
-
__contains__(name)[source]¶ Returns if
nameis inself._infoor in the frame packetself._protos.- Parameters
name (Any) – name to search
- Returns
if
nameexists- Return type
-
__getitem__(key)[source]¶ Subscription (
getitem) support.This method fist checks if
keyexists inself._info. If so, returns the corresponding value, else calls the original__getitem__()method.
-
__index__()[source]¶ Index of the protocol.
- Returns
If the object is initiated, i.e.
self._fnumexists, returns the frame index number of itself; else raisesUnsupportedCall.- Return type
- Raises
UnsupportedCall – This protocol has no registry entry.
-
__post_init__(file=None, length=None, *, num, proto, nanosecond, **kwargs)[source]¶ Initialisation.
- Parameters
file (Optional[io.BytesIO]) – Source packet stream.
length (Optional[int]) – Length of packet data.
- Keyword Arguments
num (int) – Frame index number (
self._fnum).proto (pcapkit.const.reg.linktype.LinkType) – Next layer protocol index (
self._prot).nanosecond (bool) – Nanosecond-timestamp PCAP flag (
self._nsec).mpfdp (multiprocessing.Queue) – Multiprocessing file descriptor queue (
self._mpfp).mpkit (multiprocessing.Namespace) – Multiprocessing auxiliaries (
self._mpkt).**kwargs – Arbitrary keyword arguments.
For multiprocessing related parameters, please refer to
pcapkit.foundation.extration.Extratorfor more information.See also
For construction argument, please refer to
make().
-
_decode_next_layer(data, length=None)[source]¶ Decode next layer protocol.
- Positional arguments:
data (dict): info buffer length (int): valid (non-padding) length
- Returns
current protocol with packet extracted
- Return type
-
_import_next_layer(proto, length, error=False)[source]¶ Import next layer extractor.
This method currently supports following protocols as registered in
LinkType:protoProtocol
1
228
229
- Parameters
proto (pcapkit.const.reg.linktype.LinkType) – next layer protocol index
length (int) – valid (non-padding) length
- Keyword Arguments
error (bool) – if function called on error
- Returns
instance of next layer
- Return type
-
index(name)[source]¶ Call
ProtoChain.index.- Parameters
name (Union[str, Protocol, Type[Protocol]]) –
nameto be searched- Returns
first index of
name- Return type
- Raises
IndexNotFound – if
nameis not present
-
make(**kwargs)[source]¶ Make frame packet data.
- Keyword Arguments
timestamp (float) – UNIX-Epoch timestamp
ts_sec (int) – timestamp seconds
ts_usec (int) – timestamp microseconds
incl_len (int) – number of octets of packet saved in file
orig_len (int) – actual length of packet
packet (bytes) – raw packet data (default:
b'')nanosecond (bool) – nanosecond-resolution file flag (default:
False)**kwargs – Arbitrary keyword arguments.
- Returns
Constructed packet data.
- Return type
-
read(length=None, **kwargs)[source]¶ Read each block after global header.
-
property
length¶ Header length of corresponding protocol.
- Return type
Literal[16]
-
Data Structure¶
Important
Following classes are only for documentation purpose.
They do NOT exist in the pcapkit module.
-
class
pcapkit.protocols.pcap.frame.DataType_Frame¶ - Bases
TypedDict
PCAP frame header.
-
frame_info: DataType_FrameInfo¶ PCAP frame information
-
time: datetime.datetime¶ timestamp
-
protocols: pcapkit.corekit.protochain.ProtoChain¶ protocol chain
-
class
pcapkit.protocols.pcap.frame.DataType_FrameInfo¶ - Bases
TypedDict
Frame information.