-1
我遇到一个程序这一行使用Python创建的ICMP PING包使用如何struck.pack()在创建包
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, my_checksum, ID, 1)
什么是“bbHHh”是指这里
我遇到一个程序这一行使用Python创建的ICMP PING包使用如何struck.pack()在创建包
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
你读了'struct'模块的文档? – chepner 2014-09-10 11:47:33
是的,我读过它,但我没有真正理解什么格式字符串的意思,直到约翰zwinck显示我的C结构。 – jithu 2014-09-10 16:35:32