MCPcopy Index your code
hub / github.com/secdev/scapy / PadField

Class PadField

scapy/fields.py:625–658  ·  view source on GitHub ↗

Add bytes after the proxified field so that it ends at the specified alignment from its beginning

Source from the content-addressed store, hash-verified

623
624
625class PadField(_FieldContainer):
626 """Add bytes after the proxified field so that it ends at the specified
627 alignment from its beginning"""
628 __slots__ = ["fld", "_align", "_padwith"]
629
630 def __init__(self, fld, align, padwith=None):
631 # type: (AnyField, int, Optional[bytes]) -> None
632 self.fld = fld
633 self._align = align
634 self._padwith = padwith or b"\x00"
635
636 def padlen(self, flen, pkt):
637 # type: (int, Packet) -> int
638 return -flen % self._align
639
640 def getfield(self,
641 pkt, # type: Packet
642 s, # type: bytes
643 ):
644 # type: (...) -> Tuple[bytes, Any]
645 remain, val = self.fld.getfield(pkt, s)
646 padlen = self.padlen(len(s) - len(remain), pkt)
647 return remain[padlen:], val
648
649 def addfield(self,
650 pkt, # type: Packet
651 s, # type: bytes
652 val, # type: Any
653 ):
654 # type: (...) -> bytes
655 sval = self.fld.addfield(pkt, b"", val)
656 return s + sval + (
657 self.padlen(len(sval), pkt) * self._padwith
658 )
659
660
661class ReversePadField(PadField):

Callers 15

nlmsgerr_rtattrClass · 0.90
ifla_af_spec_rtattrClass · 0.90
ifinfomsg_rtattrClass · 0.90
ifaddrmsg_rtattrClass · 0.90
rtmsg_rtattrClass · 0.90
__init__Method · 0.90
if_msghdrClass · 0.90
ifa_msghdrClass · 0.90
rt_msghdrClass · 0.90
IFETlvClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected