def METHOD_NAME(packet):
    """Calculates the checksum of a (ICMP) packet.
    RFC792 states: 'The 16 bit one's complement of the one's complement sum of
    all 16 bit words in the header.'
    Based on in_chksum found in ping.c on FreeBSD.
    """
    # add byte if not dividable by 2
    if len(packet) & 1:
        packet = packet + b'\0'
    # split into 16-bit word and insert into a binary array
    words = array.array('h', packet)
    sum_ = 0
    # perform ones complement arithmetic on 16-bit words
    for word in words:
        sum_ += word & 0xFFFF
    high = sum_ >> 16
    low = sum_ & 0xFFFF
    sum_ = high + low
    sum_ = sum_ + (sum_ >> 16)
    return (~sum_) & 0xFFFF  # return ones complement