0

i encounter this line in a program for creating icmp ping packets in python

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

what does "bbHHh" means here

chepner
  • 497,756
  • 71
  • 530
  • 681
jithu
  • 111
  • 2
  • 13

2 Answers2

2

The documentation is here: https://docs.python.org/2/library/struct.html - it's a format string. Your particular example means the equivalent of this in C:

 struct Foo {
   signed char a;
   signed char b;
   unsigned short c;
   unsigned short d;
   short e;
 }
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

Check here: https://docs.python.org/2/library/struct.html#format-characters

it means that

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
gosom
  • 1,299
  • 3
  • 16
  • 35