0

我在 python 中创建 icmp ping 数据包的程序中遇到了这一行

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

“bbHHh”在这里是什么意思

4

2 回答 2

2

文档在这里: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;
 }
于 2014-09-10T11:21:02.643 回答
1

在这里查看: 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
于 2014-09-10T11:22:24.283 回答