-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