Skip to content

Commit

Permalink
Merge pull request #26 from dkaplan1/fix_header_struct_formatting
Browse files Browse the repository at this point in the history
Update header unpack formatting to fix ICMPv6 requests
  • Loading branch information
anton-belousov authored Jul 11, 2023
2 parents 79398b7 + c9f7eec commit 8a78f9d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aioping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def receive_one_ping(my_socket, id_, timeout):
icmp_header = rec_packet[offset:offset + 8]

type, code, checksum, packet_id, sequence = struct.unpack(
"BbHHh", icmp_header
"BBHHH", icmp_header
)

if type != ICMP_ECHO_REPLY and type != ICMP6_ECHO_REPLY:
Expand Down Expand Up @@ -209,7 +209,7 @@ async def send_one_ping(my_socket, dest_addr, id_, timeout, family):
my_checksum = 0

# Make a dummy header with a 0 checksum.
header = struct.pack("BbHHh", icmp_type, 0, my_checksum, id_, 1)
header = struct.pack("BBHHH", icmp_type, 0, my_checksum, id_, 1)
bytes_in_double = struct.calcsize("d")
data = (192 - bytes_in_double) * "Q"
data = struct.pack("d", default_timer()) + data.encode("ascii")
Expand All @@ -220,7 +220,7 @@ async def send_one_ping(my_socket, dest_addr, id_, timeout, family):
# Now that we have the right checksum, we put that in. It's just easier
# to make up a new header than to stuff it into the dummy.
header = struct.pack(
"BbHHh", icmp_type, 0, socket.htons(my_checksum), id_, 1
"BBHHH", icmp_type, 0, socket.htons(my_checksum), id_, 1
)
packet = header + data

Expand Down

0 comments on commit 8a78f9d

Please sign in to comment.