<commit_before>cdef class ip(object):
    cdef public str srcip
    cdef public str dstip
    cdef public str payload

    def __init__(self, message msg):
        cdef nmsg_res res
        cdef unsigned etype
        cdef nmsg_ipdg dg

        if msg.vid != 1 or msg.msgtype != 1:
            raise Exception, 'not an ISC/ncap message'

        mtype = msg['type'][0]

        if mtype == 2: # legacy ncap
            self.srcip = msg['srcip']
            self.dstip = msg['dstip']
            self.payload = msg['payload']
        elif mtype == 0 or mtype == 1: # IPv4, IPv6
            if mtype == 0:
                etype = 0x0800 # ETHERTYPE_IP
            elif mtype == 1:
                etype = 0x86dd # ETHERTYPE_IPV6
            res = nmsg_ipdg_parse(&dg, etype, len(msg['payload'][0]), <unsigned char *> PyString_AsString(msg['payload'][0]))
            if res != nmsg_res_success:
                raise Exception, 'nmsg_ipdg_parse() failed'
            self.payload = PyString_FromStringAndSize(<char *> dg.payload, dg.len_payload)

def print_nmsg_header(m, out):<commit_msg>pynmsg: access payload fields correctly in the nmsg.ip constructor<commit_after>cdef class ip(object):
    cdef public str srcip
    cdef public str dstip
    cdef public str payload

    def __init__(self, message msg):
        cdef nmsg_res res
        cdef unsigned etype
        cdef nmsg_ipdg dg

        if msg.vid != 1 or msg.msgtype != 1:
            raise Exception, 'not an ISC/ncap message'

        mtype = msg['type'][0]

        if mtype == 2: # legacy ncap
            self.srcip = msg['srcip'][0]
            self.dstip = msg['dstip'][0]
            self.payload = msg['payload'][0]
        elif mtype == 0 or mtype == 1: # IPv4, IPv6
            if mtype == 0:
                etype = 0x0800 # ETHERTYPE_IP
            elif mtype == 1:
                etype = 0x86dd # ETHERTYPE_IPV6
            res = nmsg_ipdg_parse(&dg, etype, len(msg['payload'][0]), <unsigned char *> PyString_AsString(msg['payload'][0]))
            if res != nmsg_res_success:
                raise Exception, 'nmsg_ipdg_parse() failed'
            self.payload = PyString_FromStringAndSize(<char *> dg.payload, dg.len_payload)

def print_nmsg_header(m, out):
{'fraction_non_alphanumeric': 0.10644007155635063, 'fraction_numerical': 0.020125223613595707, 'mean_word_length': 2.089779005524862, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1417397', 'n_tokens_mistral': 761, 'n_tokens_neox': 705, 'n_words': 195}