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

Method haslayer

scapy/packet.py:1289–1315  ·  view source on GitHub ↗

true if self has a layer that is an instance of cls. Superseded by "cls in self" syntax.

(self, cls, _subclass=None)

Source from the content-addressed store, hash-verified

1287 return layers
1288
1289 def haslayer(self, cls, _subclass=None):
1290 # type: (Union[Type[Packet], str], Optional[bool]) -> int
1291 """
1292 true if self has a layer that is an instance of cls.
1293 Superseded by "cls in self" syntax.
1294 """
1295 if _subclass is None:
1296 _subclass = self.match_subclass or None
1297 if _subclass:
1298 match = issubtype
1299 else:
1300 match = lambda x, t: bool(x == t)
1301 if cls is None or match(self.__class__, cls) \
1302 or cls in [self.__class__.__name__, self._name]:
1303 return True
1304 for f in self.packetfields:
1305 fvalue_gen = self.getfieldval(f.name)
1306 if fvalue_gen is None:
1307 continue
1308 if not f.islist:
1309 fvalue_gen = SetGen(fvalue_gen, _iterpacket=0)
1310 for fvalue in fvalue_gen:
1311 if isinstance(fvalue, Packet):
1312 ret = fvalue.haslayer(cls, _subclass=_subclass)
1313 if ret:
1314 return ret
1315 return self.payload.haslayer(cls, _subclass=_subclass)
1316
1317 def getlayer(self,
1318 cls, # type: Union[int, Type[Packet], str]

Callers 15

__contains__Method · 0.95
sprintfMethod · 0.95
__repr__Method · 0.45
hexrawMethod · 0.45
paddingMethod · 0.45
nzpaddingMethod · 0.45
igmpizeMethod · 0.45
_scanMethod · 0.45
playFunction · 0.45
packet2p0fFunction · 0.45
p0f_impersonateFunction · 0.45
validate_packetFunction · 0.45

Calls 2

getfieldvalMethod · 0.95
SetGenClass · 0.90

Tested by

no test coverage detected