def test_from_bytes_selftest(self, subject): """Test if it can parse its own output""" p = self.saturated_packet() p2 = Ipv4RawPacket.from_bytes(bytes(p)) msg = "Packets are not equal:\n\np1:\n{}\np2:\n{}".format( p.diagram(with_lines=True, with_captions=True), p2.diagram(with_lines=True) ) assert p2 == p, msg
def example_packet(self): """Returns the example packet from this Wikipedia entry: https://en.wikipedia.org/wiki/IPv4_header_checksum """ packet_hex = [ # Header "45", "00", "00", "73", "00", "00", "40", "00", "40", "11", "b8", "61", "c0", "a8", "00", "01", "c0", "a8", "00", "c7", # Payload "00", "35", "e9", "7c", "00", "5f", "27", "9f", "1e", "4b", "81", "80" ] packet_bytes = bytes(int(x, 16) for x in packet_hex) return Ipv4RawPacket.from_bytes(packet_bytes)