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

Method _fix

scapy/layers/inet.py:367–394  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

365 self.size = size
366
367 def _fix(self):
368 # Pseudo-Random amount of options
369 # Random ("NAME", fmt)
370 rand_patterns = [
371 random.choice(list(
372 (opt, fmt) for opt, fmt in TCPOptions[0].values()
373 if opt != 'EOL'
374 ))
375 for _ in range(self.size)
376 ]
377 rand_vals = []
378 for oname, fmt in rand_patterns:
379 if fmt is None:
380 rand_vals.append((oname, b''))
381 else:
382 # Process the fmt arguments 1 by 1
383 structs = re.findall(r"!?([bBhHiIlLqQfdpP]|\d+[spx])", fmt)
384 rval = []
385 for stru in structs:
386 stru = "!" + stru
387 if "s" in stru or "p" in stru: # str / chr
388 v = bytes(RandBin(struct.calcsize(stru)))
389 else: # int
390 _size = struct.calcsize(stru)
391 v = random.randint(0, 2 ** (8 * _size) - 1)
392 rval.append(v)
393 rand_vals.append((oname, tuple(rval)))
394 return rand_vals
395
396 def __bytes__(self):
397 return TCPOptionsField.i2m(None, None, self._fix())

Callers 9

__bytes__Method · 0.95
__init__Method · 0.45
__init__Method · 0.45
create_requestMethod · 0.45
_base_kdc_reqMethod · 0.45
as_reqMethod · 0.45
GSS_Init_sec_contextMethod · 0.45
BEGINMethod · 0.45
BEGINMethod · 0.45

Calls 4

RandBinClass · 0.90
choiceMethod · 0.80
valuesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected