<commit_before>"""
IP protocol definitions.
"""

import binascii
import ctypes
import struct


class IP(ctypes.Structure):
    """
    Represents an IP packet.
    """

    _fields_ = [('v', ctypes.c_ushort),         # version
                ('hl', ctypes.c_ushort),        # internet header length
                ('tos', ctypes.c_ubyte),        # type of service
                ('len', ctypes.c_ushort),       # total length
                ('id', ctypes.c_ushort),        # IPID
                ('flags', ctypes.c_ushort, 3),  # flags
                ('off', ctypes.c_ushort, 13),   # fragmentation offset
                ('ttl', ctypes.c_ubyte),        # TTL
                ('p', ctypes.c_ubyte),          # protocol
                ('sum', ctypes.c_ushort),       # checksum
                ('src', ctypes.c_char_p),       # source address
                ('dst', ctypes.c_char_p),       # destination address
                ('opt', ctypes.c_char_p),       # IP options
                ('pad', ctypes.c_char_p),       # padding bytes
                ('payload', ctypes.c_char_p)]   # packet payload

    def __init__(self, packet, layers=0):
        # parse the required header first, deal with options later
        magic = struct.unpack('!b',packet[0])[0]
        assert ((magic & 0b1100) == 4 and
                (magic & 0b0111) > 4), 'not an IPv4 packet.'

        fields = struct.unpack('!BBHHHBBHII', packet[:20])
        self.v = fields[0] & 0b1100
        self.hl = fields[0] & 0b0111
        self.tos = fields[1]
        self.len = fields[2]<commit_msg>Fixed unpack for python3<commit_after>"""
IP protocol definitions.
"""

import binascii
import ctypes
import struct


class IP(ctypes.Structure):
    """
    Represents an IP packet.
    """

    _fields_ = [('v', ctypes.c_ushort),         # version
                ('hl', ctypes.c_ushort),        # internet header length
                ('tos', ctypes.c_ubyte),        # type of service
                ('len', ctypes.c_ushort),       # total length
                ('id', ctypes.c_ushort),        # IPID
                ('flags', ctypes.c_ushort, 3),  # flags
                ('off', ctypes.c_ushort, 13),   # fragmentation offset
                ('ttl', ctypes.c_ubyte),        # TTL
                ('p', ctypes.c_ubyte),          # protocol
                ('sum', ctypes.c_ushort),       # checksum
                ('src', ctypes.c_char_p),       # source address
                ('dst', ctypes.c_char_p),       # destination address
                ('opt', ctypes.c_char_p),       # IP options
                ('pad', ctypes.c_char_p),       # padding bytes
                ('payload', ctypes.c_char_p)]   # packet payload

    def __init__(self, packet, layers=0):
        # parse the required header first, deal with options later
        magic = struct.unpack('!B',packet[0:1])[0]
        assert ((magic & 0b1100) == 4 and
                (magic & 0b0111) > 4), 'not an IPv4 packet.'

        fields = struct.unpack('!BBHHHBBHII', packet[:20])
        self.v = fields[0] & 0b1100
        self.hl = fields[0] & 0b0111
        self.tos = fields[1]
        self.len = fields[2]
{'fraction_non_alphanumeric': 0.13272093759898637, 'fraction_numerical': 0.022806461830852075, 'mean_word_length': 1.6808149405772497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7637572', 'n_tokens_mistral': 1041, 'n_tokens_neox': 957, 'n_words': 232}