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

Method getfield

scapy/fields.py:2141–2175  ·  view source on GitHub ↗
(self,
                 pkt,  # type: Packet
                 s,  # type: bytes
                 )

Source from the content-addressed store, hash-verified

2139 return s
2140
2141 def getfield(self,
2142 pkt, # type: Packet
2143 s, # type: bytes
2144 ):
2145 # type: (...) -> Any
2146 c = len_pkt = None
2147 if self.length_from is not None:
2148 len_pkt = self.length_from(pkt)
2149 elif self.count_from is not None:
2150 c = self.count_from(pkt)
2151
2152 val = []
2153 ret = b""
2154 if len_pkt is not None:
2155 s, ret = s[:len_pkt], s[len_pkt:]
2156
2157 while s:
2158 if c is not None:
2159 if c <= 0:
2160 break
2161 c -= 1
2162 s, v = self.field.getfield(pkt, s)
2163 val.append(v)
2164 if len(val) > (self.max_count or conf.max_list_count):
2165 raise MaximumItemsCount(
2166 "Maximum amount of items reached in FieldListField: %s "
2167 "(defaults to conf.max_list_count)"
2168 % (self.max_count or conf.max_list_count)
2169 )
2170
2171 if isinstance(s, tuple):
2172 s, bn = s
2173 return (s + ret, bn), val
2174 else:
2175 return s + ret, val
2176
2177
2178class FieldLenField(Field[int, int]):

Callers

nothing calls this directly

Calls 4

MaximumItemsCountClass · 0.85
length_fromMethod · 0.45
getfieldMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected