예제 #1
0
파일: pkt.py 프로젝트: n1ywb/mi-instrument
 def stuff(self):
     # create Packet struct HERE and ALWAYS free it
     # how does this report failure? I guess the only conceivable failure
     # mode is OOM.
     pkt = None
     pfptr = None
     try:
         pkt = _pkt.newPkt()
         if pkt is None:
             raise RuntimeError("newPkt failure")
         # set pkt fields using raw api
         _pkt._Pkt_pkttype_set(pkt, self.pkttype['suffix'])
         _pkt._Pkt_srcnameparts_set(pkt, *[self.srcnameparts[k] for k in
             self._srcnamefields])
         _pkt._Pkt.time_set(pkt, self.time)
         # stuff packet
         if self.pfdict is not None:
             # make a new pf
             pfptr = _stock.pfnew()
             if pfptr is None:
                 raise RuntimeError("pfnew")
             # copy pfdict into new pf
             # TODO this might not actually work, might have to iterate over
             # items and put each one.
             _stock.pfput(None, self.pfdict, pfptr)
             # attach pfptr to pkt
             _pkt._Pkt_pfptr_set(pkt, pfptr)
         type, packet, srcname, time = _pkt._stuffPkt(pkt)
         return type, packet, srcname, time
     finally:
         if pkt is not None:
             _pkt._freePkt(pkt)
         if pfptr is not None:
             _stock.pffree(pfptr)
예제 #2
0
파일: pkt.py 프로젝트: n1ywb/mi-instrument
 def unstuff(self, srcname, time, raw_packet):
     pkt = None
     try:
         type, pkt = _pkt._unstuffPkt(srcname, time, raw_packet)
         check_error(type, UnstuffError)
         self.string = _pkt._Pkt_string_get(pkt)
         self.pkttype.update(dict(zip(self._pkttypefields,
             _pkt._Pkt_pkttype_get(pkt))))
         if _pkt._Pkt_type_get(pkt) == _pkt.Pkt_pf:
             pfptr = _pkt._Pkt_pfptr_get(pkt)
             if pfptr != None:
                 try:
                     self.pfdict = _stock._pfget(pfptr, None)
                 finally:
                     _stock._pffree(pfptr)
         self.time = time
     finally:
         if pkt is not None:
             _pkt._freePkt(pkt)