identification, flags_offset, ttl, protocol, checksum = struct.unpack('!HHBBH', ip_packet[4:10]) unpack requires a buffer of 8 bytes
时间: 2024-05-21 14:17:12 浏览: 150
Python库 | feature_flags_client-1.0.18.dev1.tar.gz
Yes, that's correct. The `struct.unpack` function requires a buffer of bytes as its first argument, and the second argument specifies the size of the buffer in bytes. In this case, the buffer size is 8 bytes because we are unpacking 6 fields, each with a specific size specified by the format string `!HHBBH`.
The `!` character at the beginning of the format string specifies that the data should be interpreted in network byte order (big-endian). The `H` format code specifies a 2-byte unsigned short integer, the `B` format code specifies a single byte, and the `checksum` field is also a 2-byte unsigned short integer, hence the total buffer size of 8 bytes.
阅读全文