Parse ICMP packet and return an instance of Packet
(cls, packet)
| 139 | return ~total |
| 140 | |
| 141 | def parse(cls, packet): |
| 142 | """Parse ICMP packet and return an instance of Packet""" |
| 143 | string_len = len(packet) - 4 # Ignore IP header |
| 144 | pack_format = "!BBH" |
| 145 | if string_len: |
| 146 | pack_format += "%ss" % string_len |
| 147 | unpacked_packet = struct.unpack(pack_format, packet) |
| 148 | type, code, checksum = unpacked_packet[:3] |
| 149 | try: |
| 150 | data = unpacked_packet[3] |
| 151 | except IndexError: |
| 152 | data = None |
| 153 | return cls((type, code), data) |
| 154 | |
| 155 | parse = classmethod(parse) |
| 156 |
no test coverage detected