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

Method addfield

scapy/fields.py:2377–2402  ·  view source on GitHub ↗
(self,  # type: ignore
                 pkt,  # type: Packet
                 s,  # type: Union[Tuple[bytes, int, int], bytes]
                 ival,  # type: I
                 )

Source from the content-addressed store, hash-verified

2375 # We need to # type: ignore a few things because of how special
2376 # BitField is
2377 def addfield(self, # type: ignore
2378 pkt, # type: Packet
2379 s, # type: Union[Tuple[bytes, int, int], bytes]
2380 ival, # type: I
2381 ):
2382 # type: (...) -> Union[Tuple[bytes, int, int], bytes]
2383 val = self.i2m(pkt, ival)
2384 if isinstance(s, tuple):
2385 s, bitsdone, v = s
2386 else:
2387 bitsdone = 0
2388 v = 0
2389 v <<= self.size
2390 v |= val & ((1 << self.size) - 1)
2391 bitsdone += self.size
2392 while bitsdone >= 8:
2393 bitsdone -= 8
2394 s = s + struct.pack("!B", v >> bitsdone)
2395 v &= (1 << bitsdone) - 1
2396 if bitsdone:
2397 return s, bitsdone, v
2398 else:
2399 # Apply LE if necessary
2400 if self.rev and self.end_tot_size > 1:
2401 s = s[:-self.end_tot_size] + s[-self.end_tot_size:][::-1]
2402 return s
2403
2404 def getfield(self, # type: ignore
2405 pkt, # type: Packet

Callers

nothing calls this directly

Calls 1

i2mMethod · 0.45

Tested by

no test coverage detected