Abstract PDU¶
-
class
PDU
¶ Bases:
object
Abstract Protocol Data Unit
To build a PDU from a buffer:
>>> buf = [ ... 170, 187, 204, 221, 238, 255, 138, 139, 140, 141, 142, 143, 208, 171, ... 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, ... 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, ... 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 ... ] >>> buf = "".join([chr(i) for i in buf]) >>> pdu = EthernetII.from_buffer(buf)
PDU objects supports equality:
>>> pdu1 = EthernetII.from_buffer(buf1) >>> pdu2 = EthernetII.from_buffer(buf2) >>> if pdu1 == pdu2: ... print("Equals")
PDU objects can be copied:
>>> import copy >>> pdu1 = EthernetII.from_buffer(buf1) >>> pdu2 = pdu.copy() >>> pdu3 = copy.copy(pdu1)
PDU objects can be pickled:
>>> import pickle >>> pdu = EthernetII.from_buffer(buf1) >>> d = pickle.dumps(pdu)
PDU can be built by concatenation:
>>> pdu = EthernetII() / IP()
PDU is abstract:
>>> from cycapture.libtins import PDU >>> pdu = PDU() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "cycapture/libtins/pdu_pyx.pxi", line 190, in cycapture.libtins._tins.PDU.__cinit__ raise NotImplementedError NotImplementedError
-
copy_inner_pdu
()¶ Returns a copy of the inner PDU, or
None
if self has no childReturns: PDU ( PDU
) -- A copy of the inner PDU
-
find_pdu
()¶ Search the successive inner PDUs
Parameters: obj (PDU class) Returns: PDU ( PDU
) -- a copy of the matching inner PDURaises: PDUNotFound
(PDUNotFound
) -- if no marching PDU is found
-
find_pdu_by_type
(int t)¶ Search the successive inner PDUs, by PDU type
Parameters: t (int) -- the type of the PDU that you're looking for Returns: PDU ( PDU
) -- a copy of the matching inner PDURaises: PDUNotFound
(PDUNotFound
) -- if no marching PDU is found
-
from_buffer
(buf)¶ Factory classmethod, to make a concrete PDU from a buffer
Parameters: buf (bytes or bytearray or memoryview or cython memoryview) Returns: PDU ( PDU
) -- The new PDURaises: MalformedPacket
(MalformedPacket
) -- if the given buffer can not be interpreted as an instance of the concrete PDUNote
Class method
-
get_pdu_type
()¶ Returns: int -- The PDU type
-
matches_response
(buf)¶ Checks if the given buffer can be a valid response to the current PDU
Parameters: buf (bytes or bytearray or memoryview or cython memoryview) Returns: bool -- True
if buf is a response to the PDU
-
ref_inner_pdu
()¶ Returns a reference to the inner PDU, or
None
if self has no childReturns: PDU ( PDU
) -- A reference of the inner PDU
-
rfind_pdu
(obj)¶ Search the successive inner PDUs
Parameters: obj (PDU class) Returns: PDU ( PDU
) -- a reference of the matching inner PDURaises: PDUNotFound
(PDUNotFound
) -- if no marching PDU is found
-
rfind_pdu_by_datalink_type
(int t)¶ Search the successive inner PDUs, by datalink type
Parameters: t (int) -- the datalink type of the PDU that you're looking for Returns: PDU ( PDU
) -- a reference of the matching inner PDURaises: PDUNotFound
(PDUNotFound
) -- if no marching PDU is found
-
rfind_pdu_by_type
(int t)¶ Search the successive inner PDUs, by PDU type
Parameters: t (int) -- the type of the PDU that you're looking for Returns: PDU ( PDU
) -- a reference of the matching inner PDURaises: PDUNotFound
(PDUNotFound
) -- if no marching PDU is found
-
serialize
()¶ Serialize the PDU
Returns: bytes -- the PDU as bytes
-
set_inner_pdu
(obj)¶ Replace the inner PDU with obj.
Note
obj
is cloned before being set as the inner PDU.Parameters: obj ( PDU
) -- the replacement PDU
-
header_size
¶ Returns the PDU's header size (read-only property)
-
size
¶ Returns the PDU's size (read-only property)
-
trailer_size
¶ Returns the PDU's trailer size (read-only property)
-