Protocol Fields#
pcapkit.corekit.fields is collection of protocol fields,
descriptive of the structure of protocol headers.
Base Field#
- class pcapkit.corekit.fields.field._Field#
Bases:
Generic[_T]Internal base class for protocol fields.
- property default: _T | NoValueType#
Field default value.
- __call__(packet)#
Update field attributes.
- Parameters:
- Return type:
- Returns:
Updated field instance.
Notes
This method will return a new instance of
_Fieldinstead of updating the current instance.
- pre_process(value, packet)#
Process field value before construction (packing).
- post_process(value, packet)#
Process field value after parsing (unpacking).
- class pcapkit.corekit.fields.field.Field(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function Field.<lambda>>)#
Bases:
_Field[_T],Generic[_T]Base class for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
Union[TypeVar(_T),NoValueType]) – Field default value, if any.callback (
Callable[[Field[TypeVar(_T)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
Auxiliary#
- pcapkit.corekit.fields.field.NoValue#
Default value for
_Field.default.- Type:
Numerical Fields#
- class pcapkit.corekit.fields.numbers.NumberField(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
Field[int],Generic[_T]Numerical value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- __call__(packet)#
Update field attributes.
- Parameters:
- Return type:
- Returns:
New instance of
NumberField.
Notes
This method will return a new instance of
NumberFieldinstead of updating the current instance.
- build_template(length, signed)#
Build template for field.
- pre_process(value, packet)#
Process field value before construction (packing).
- class pcapkit.corekit.fields.numbers.Int32Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldInteger value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.UInt32Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldUnsigned integer value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.Int16Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldShort integer value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.UInt16Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldUnsigned short integer value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.Int64Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldLong integer value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.UInt64Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldUnsigned long integer value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.Int8Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldByte value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.UInt8Field(length=None, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, callback=<function NumberField.<lambda>>)#
Bases:
NumberFieldUnsigned byte value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int],None]) – Field size (in bytes).default (
int|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.callback (
Callable[[NumberField[TypeVar(_T, bound= int)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.numbers.EnumField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, signed=False, byteorder='big', bit_length=None, namespace=None, callback=<function EnumField.<lambda>>)#
Bases:
NumberField[IntEnum|IntEnum]Enumerated value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
IntEnum|IntEnum|NoValueType) – Field default value, if any.signed (
bool) – Whether the field is signed.byteorder (
Literal['little','big']) – Field byte order.namespace (
Union[Type[IntEnum],Type[IntEnum],None]) – Field namespace (aenum.IntEnumclass).callback (
Callable[[EnumField,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
Text Fields#
- class pcapkit.corekit.fields.strings._TextField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function _TextField.<lambda>>)#
-
Internal text value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
Union[TypeVar(_T, str, bytes, dict[str, Any]),NoValueType]) – Field default value, if any.callback (
Callable[[_TextField[TypeVar(_T, str, bytes, dict[str, Any])],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- __call__(packet)#
Update field attributes.
- Parameters:
- Return type:
- Returns:
New instance of
_TextField.
Notes
This method will return a new instance of
_TextFieldinstead of updating the current instance.
- class pcapkit.corekit.fields.strings.BytesField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function _TextField.<lambda>>)#
Bases:
_TextField[bytes]Bytes value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
Union[TypeVar(_T, str, bytes, dict[str, Any]),NoValueType]) – Field default value, if any.callback (
Callable[[_TextField[TypeVar(_T, str, bytes, dict[str, Any])],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.strings.StringField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, encoding=None, errors='strict', unquote=False, callback=<function StringField.<lambda>>)#
Bases:
_TextField[str]String value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
str|NoValueType) – Field default value, if any.encoding (
Optional[str]) – The encoding with which to decode thebytes. If not provided,pcapkitwill first try detecting its encoding usingchardet. The fallback encoding would is UTF-8.errors (
Literal['strict','ignore','replace']) – The error handling scheme to use for the handling of decoding errors. The default is'strict'meaning that decoding errors raise aUnicodeDecodeError. Other possible values are'ignore'and'replace'as well as any other name registered withcodecs.register_error()that can handleUnicodeDecodeError.unquote (
bool) – Whether to unquote the decoded string as a URL. Should decoding failed , the method will try again replacing'%'with'\x'then decoding theurlas'utf-8'with'replace'for error handling.callback (
Callable[[StringField,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- pre_process(value, packet)#
Process field value before construction (packing).
- class pcapkit.corekit.fields.strings.BitField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, namespace=None, callback=<function BitField.<lambda>>)#
Bases:
_TextField[dict[str,Any]]Bit value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
dict[str,Any] |NoValueType) – Field default value, if any.namespace (
Optional[dict[str,Tuple[int,int]]]) – Field namespace (a dict mapping field name to a tuple of start index, and length of the subfield).callback (
Callable[[BitField,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- pre_process(value, packet)#
Process field value before construction (packing).
- class pcapkit.corekit.fields.strings.PaddingField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function _TextField.<lambda>>)#
Bases:
BytesFieldBytes value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
Union[TypeVar(_T, str, bytes, dict[str, Any]),NoValueType]) – Field default value, if any.callback (
Callable[[_TextField[TypeVar(_T, str, bytes, dict[str, Any])],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
IP Address Fields#
- class pcapkit.corekit.fields.ipaddress._IPField(length, default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function Field.<lambda>>)#
Bases:
Field[_T]Internal IP address value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
Union[TypeVar(_T),NoValueType]) – Field default value, if any.callback (
Callable[[Field[TypeVar(_T)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- pre_process(value, packet)#
Process field value before packing.
- class pcapkit.corekit.fields.ipaddress.IPv4Field(default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function IPv4Field.<lambda>>)#
Bases:
_IPField[IPv4Address]IPv4 address value for protocol fields.
- Parameters:
default (
IPv4Address|NoValueType) – Field default value, if any.callback (
Callable[[IPv4Field,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- class pcapkit.corekit.fields.ipaddress.IPv6Field(default=<pcapkit.corekit.fields.field.NoValueType object>, callback=<function IPv6Field.<lambda>>)#
Bases:
_IPField[IPv6Address]IPv6 address value for protocol fields.
- Parameters:
default (
IPv6Address|NoValueType) – Field default value, if any.callback (
Callable[[IPv6Field,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
Container Fields#
- class pcapkit.corekit.fields.collections.ListField(length=<function ListField.<lambda>>, item_type=None, callback=<function ListField.<lambda>>)#
-
Field list for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.item_type (
Optional[_Field]) – Field type of the contained items.callback (
Callable[[ListField,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
This field is used to represent a list of fields, as in the case of lists of constrant-length-field items in a protocol.
- __call__(packet)#
Update field attributes.
- Parameters:
- Return type:
- Returns:
Updated field instance.
Notes
This method will return a new instance of
ListFieldinstead of updating the current instance.
- class pcapkit.corekit.fields.collections.OptionField(length=<function OptionField.<lambda>>, base_schema=None, type_name='type', registry=None, eool=None, callback=<function OptionField.<lambda>>)#
Bases:
ListFieldField list for protocol options.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.base_schema (
Optional[Type[Schema]]) – Base schema for option fields.type_name (
str) – Name of the option type field.registry (
Optional[defaultdict[int|IntEnum|IntEnum,Type[Schema]]]) – Option registry, as in a mapping from option types (enumeration values) to option schemas, with the default value being the unknown option schema.eool (
Union[int,IntEnum,IntEnum,None]) – Enumeration of the EOOL (end-of-option-list, or equivalent) optioncallback (
Callable[[ListField,dict[str,Any]],None]) – Callback function to be called uponself.__call__.
This field is used to represent a list of fields, as in the case of lists of options and/or parameters in a protocol.
Miscellaneous Fields#
- class pcapkit.corekit.fields.misc.ConditionalField(field, condition)#
Bases:
_Field[_TC]Conditional value for protocol fields.
- Parameters:
- property default: _TC | NoValueType#
Field default value.
- __call__(packet)#
Update field attributes.
- Parameters:
- Return type:
- Returns:
Updated field instance.
Notes
This method will return a new instance of
ConditionalFieldinstead of updating the current instance.
- pre_process(value, packet)#
Process field value before construction (packing).
- post_process(value, packet)#
Process field value after parsing (unpacking).
- class pcapkit.corekit.fields.misc.PayloadField(length=<function PayloadField.<lambda>>, default=<pcapkit.corekit.fields.field.NoValueType object>, protocol=None, callback=<function PayloadField.<lambda>>)#
Bases:
_Field[_TP]Payload value for protocol fields.
- Parameters:
length (
Union[int,Callable[[dict[str,Any]],int]]) – Field size (in bytes); if a callable is given, it should return an integer value and accept the current packet as its only argument.default (
Union[TypeVar(_TP, bound= Protocol),NoValueType,bytes]) – Field default value.protocol (
Optional[Type[TypeVar(_TP, bound= Protocol)]]) – Payload protocol.callback (
Callable[[PayloadField[TypeVar(_TP, bound= Protocol)],dict[str,Any]],None]) – Callback function to be called uponself.__call__.
- __call__(packet)#
Update field attributes.
- Parameters:
- Return type:
- Returns:
Updated field instance.
Notes
This method will return a new instance of
PayloadFieldinstead of updating the current instance.
- class pcapkit.corekit.fields.misc.SwitchField(length=<function SwitchField.<lambda>>, selector=<function SwitchField.<lambda>>)#
Bases:
_Field[_TC]Conditional type-switching field for protocol schema.
- Parameters:
- __call__(packet)#
Call field.
- Parameters:
- Return type:
SwitchField[TypeVar(_TC)]- Returns:
New field instance.
Notes
This method will return a new instance of
SwitchFieldinstead of updating the current instance.
- pre_process(value, packet)#
Process field value before construction (packing).
- post_process(value, packet)#
Process field value after parsing (unpacking).
- class pcapkit.corekit.fields.misc.ForwardMatchField(field)#
Bases:
_Field[_TC]Schema field for non-capturing forward matching.
- property default: _TC | NoValueType#
Field default value.