For my Computer Networking class, I am trying to implement Traceroute using raw ICMP sockets. I need to create a package and then unzip the response package using the Python structure class. Here is the code to create the package:
header = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, myChecksum, pid, 1) data = struct.pack("d", time.time()) packet = header + data
Later I receive an ICMP packet in the same format with confirmation. Here is the code to unpack the package:
request_code, request_type, checksum, packet_id, \ sequence, timeSent, data = struct.unpack("bbHHhd", recvPacket)
But I get the following error: struct.error: unpack requires a string argument of length 16 .
I do not understand, because when I check struct.calcsize() on a format string, it returns 16.
Here is my complete program if you want to run it on your computer.
from socket import * import socket import os import sys import struct import time import select import binascii ICMP_ECHO_REQUEST = 8 MAX_HOPS = 30 TIMEOUT = 2.0 TRIES = 2
source share