我在 python 中创建 icmp ping 数据包的程序中遇到了这一行
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, my_checksum, ID, 1)
“bbHHh”在这里是什么意思
我在 python 中创建 icmp ping 数据包的程序中遇到了这一行
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, my_checksum, ID, 1)
“bbHHh”在这里是什么意思
文档在这里:https ://docs.python.org/2/library/struct.html - 这是一个格式字符串。您的特定示例在 C 中与此等效:
struct Foo {
signed char a;
signed char b;
unsigned short c;
unsigned short d;
short e;
}
在这里查看: https ://docs.python.org/2/library/struct.html#format-characters
代表着
ICMP_ECHO_REQUEST is a signed char -> integer in python
0 the same
my_checksum is unsigned short -> integer in python
ID the same
h is a short -> integer in python