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

Class FieldLenField

scapy/fields.py:2178–2212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2176
2177
2178class FieldLenField(Field[int, int]):
2179 __slots__ = ["length_of", "count_of", "adjust"]
2180
2181 def __init__(
2182 self,
2183 name, # type: str
2184 default, # type: Optional[Any]
2185 length_of=None, # type: Optional[str]
2186 fmt="H", # type: str
2187 count_of=None, # type: Optional[str]
2188 adjust=lambda pkt, x: x, # type: Callable[[Packet, int], int]
2189 ):
2190 # type: (...) -> None
2191 Field.__init__(self, name, default, fmt)
2192 self.length_of = length_of
2193 self.count_of = count_of
2194 self.adjust = adjust
2195
2196 def i2m(self, pkt, x):
2197 # type: (Optional[Packet], Optional[int]) -> int
2198 if x is None and pkt is not None:
2199 if self.length_of is not None:
2200 fld, fval = pkt.getfield_and_val(self.length_of)
2201 f = fld.i2len(pkt, fval)
2202 elif self.count_of is not None:
2203 fld, fval = pkt.getfield_and_val(self.count_of)
2204 f = fld.i2count(pkt, fval)
2205 else:
2206 raise ValueError(
2207 "Field should have either length_of or count_of"
2208 )
2209 x = self.adjust(pkt, f)
2210 elif x is None:
2211 x = 0
2212 return x
2213
2214
2215class StrNullField(StrField):

Callers 15

nlmsgerr_rtattrClass · 0.90
ifla_af_spec_rtattrClass · 0.90
ifinfomsg_rtattrClass · 0.90
ifaddrmsg_rtattrClass · 0.90
rtmsg_rtattrClass · 0.90
IFETlvClass · 0.90
IFETlvStrClass · 0.90
IFEClass · 0.90
SDESItemClass · 0.90
VQPEntryClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected