コード例 #1
0
ファイル: nidtnmetadata.py プロジェクト: skunkwerks/netinf
    def init_from_net(self, inputstr):
        """
        @brief Unpack string into instance variables - validation later
        @param inputstr string block as received from network
        @return boolean - True if initialization succeeds
        """
        offset = 0
        input_len = len(inputstr)
        used_len = 0

        try:
            (used_len, self.ontology) = unpack_from("!v", inputstr,
                                                    offset = offset)
            offset = used_len
            if (offset > input_len):
                raise struct_error("Input string too short at ontology")

            self.ontology_data = inputstr[offset : ]

        except Exception, e:
            return False
コード例 #2
0
ファイル: nidtnbpq.py プロジェクト: skunkwerks/netinf
    def init_from_net(self, inputstr):
        """
        @brief Unpack string into instance variables - validation later
        @param inputstr string block as received from network
        @return boolean - True if initialization succeeds
        """
        offset = 0
        input_len = len(inputstr)
        used_len = 0

        try:
            (used_len, self.bpq_kind, self.matching_rule,
             self.creation_ts, self.creation_seq,
             self.src_eid_len) = unpack_from("!BBvvv", inputstr,
                                             offset = offset)
            offset = used_len
            if ((offset + self.src_eid_len) > input_len):
                raise struct_error("Input string too short at src_eid")

            self.src_eid = inputstr[offset : (offset + self.src_eid_len)]

            offset += self.src_eid_len
            (used_len, self.bpq_id_len) = unpack_from("!v", inputstr,
                                                      offset = offset)
            offset += used_len
            if ((offset + self.bpq_id_len) > input_len):
                raise struct_error("Input string too short at bpq_id")

            self.bpq_id = inputstr[offset : (offset + self.bpq_id_len)]

            offset += self.bpq_id_len
            (used_len, self.bpq_val_len) = unpack_from("!v", inputstr,
                                                       offset = offset)
            
            offset += used_len
            if ((offset + self.bpq_val_len) > input_len):
                raise struct_error("Input string too short at bpq_val")

            self.bpq_val = inputstr[offset : (offset + self.bpq_val_len)]

            offset += self.bpq_val_len
            (used_len, self.frag_cnt) = unpack_from("!v", inputstr,
                                                    offset = offset)
            offset += used_len

            self.frag_desc = []

            if self.frag_cnt > 0:
                fmt_str = "!" + ("vv" * self.frag_cnt)
                frag_tuple = unpack_from(fmt_str, inputstr, offset = offset)
                offset += frag_tuple[0]
                i = 0
                j = 1
                while (i < self.frag_cnt):
                    d = {}
                    d["frag_offset"] = frag_tuple[j]
                    j += 1
                    d["frag_len"] = frag_tuple[j]
                    j += 1
                    self.frag_desc.append(d)
                    i += 1
            if (offset != input_len):
                raise struct_error("Input string is wrong length")
        except Exception, e:
            return False