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

Class StrLenField

scapy/fields.py:1970–2003  ·  view source on GitHub ↗

StrField with a length :param length_from: a function that returns the size of the string :param max_length: max size to use as randval

Source from the content-addressed store, hash-verified

1968
1969
1970class StrLenField(StrField):
1971 """
1972 StrField with a length
1973
1974 :param length_from: a function that returns the size of the string
1975 :param max_length: max size to use as randval
1976 """
1977 __slots__ = ["length_from", "max_length"]
1978 ON_WIRE_SIZE_UTF16 = True
1979
1980 def __init__(
1981 self,
1982 name, # type: str
1983 default, # type: bytes
1984 length_from=None, # type: Optional[Callable[[Packet], int]]
1985 max_length=None, # type: Optional[Any]
1986 ):
1987 # type: (...) -> None
1988 super(StrLenField, self).__init__(name, default)
1989 self.length_from = length_from
1990 self.max_length = max_length
1991
1992 def getfield(self, pkt, s):
1993 # type: (Any, bytes) -> Tuple[bytes, bytes]
1994 len_pkt = (self.length_from or (lambda x: 0))(pkt)
1995 if not self.ON_WIRE_SIZE_UTF16:
1996 len_pkt *= 2
1997 if len_pkt == 0:
1998 return s, b""
1999 return s[len_pkt:], self.m2i(pkt, s[:len_pkt])
2000
2001 def randval(self):
2002 # type: () -> RandBin
2003 return RandBin(RandNum(0, self.max_length or 1200))
2004
2005
2006class _XStrField(Field[bytes, bytes]):

Callers 15

nlmsgerr_rtattrClass · 0.90
ifinfomsg_rtattrClass · 0.90
ifaddrmsg_rtattrClass · 0.90
sockaddrClass · 0.90
_CoAPOptClass · 0.90
CoAPClass · 0.90
GeneveOptionsClass · 0.90
SDESItemClass · 0.90
VQPEntryClass · 0.90
MQTTSNGwInfoClass · 0.90
MQTTSNConnectClass · 0.90
MQTTSNWillTopicClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected