2014-09-10 63 views
-1

我遇到一个程序这一行使用Python创建的ICMP PING包使用如何struck.pack()在创建包

header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, my_checksum, ID, 1) 

什么是“bbHHh”是指这里

+0

你读了'struct'模块的文档? – chepner 2014-09-10 11:47:33

+0

是的,我读过它,但我没有真正理解什么格式字符串的意思,直到约翰zwinck显示我的C结构。 – jithu 2014-09-10 16:35:32

回答

1

的文档是在这里: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; 
}