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

Function fletcher16_checkbytes

scapy/utils.py:631–658  ·  view source on GitHub ↗

Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string. Including the bytes into the buffer (at the position marked by offset) the # noqa: E501 global Fletcher-16 checksum of the buffer will be 0. Thus it is easy to verify # noqa: E501 the integrity of the buf

(binbuf, offset)

Source from the content-addressed store, hash-verified

629
630@conf.commands.register
631def fletcher16_checkbytes(binbuf, offset):
632 # type: (bytes, int) -> bytes
633 """Calculates the Fletcher-16 checkbytes returned as 2 byte binary-string.
634
635 Including the bytes into the buffer (at the position marked by offset) the # noqa: E501
636 global Fletcher-16 checksum of the buffer will be 0. Thus it is easy to verify # noqa: E501
637 the integrity of the buffer on the receiver side.
638
639 For details on the algorithm, see RFC 2328 chapter 12.1.7 and RFC 905 Annex B. # noqa: E501
640 """
641
642 # This is based on the GPLed C implementation in Zebra <http://www.zebra.org/> # noqa: E501
643 if len(binbuf) < offset:
644 raise Exception("Packet too short for checkbytes %d" % len(binbuf))
645
646 binbuf = binbuf[:offset] + b"\x00\x00" + binbuf[offset + 2:]
647 (c0, c1) = _fletcher16(binbuf)
648
649 x = ((len(binbuf) - offset - 1) * c0 - c1) % 255
650
651 if (x <= 0):
652 x += 255
653
654 y = 510 - c0 - x
655
656 if (y > 255):
657 y -= 255
658 return chb(x) + chb(y)
659
660
661def mac2str(mac):

Callers 2

post_buildMethod · 0.90
ospf_lsa_checksumFunction · 0.90

Calls 2

chbFunction · 0.90
_fletcher16Function · 0.85

Tested by

no test coverage detected