def read_handler(self): ip = struct.unpack("!I", self.recv(4))[0] # network byte-order port = struct.unpack("!H", self.recv(2))[0] # network byte-order length = struct.unpack("i", self.recv(4))[0] # host byte-order src = IpAddress(ip) src.port = port msg = self.recv(length) assert length == len(msg) tlv = BER_decode.get_tlv(msg) # should be community based message version, community, pdu = tlv.decode() if version == 0: pdu = _translate2v2(ip, community, pdu) tr = TrapRecord(now(), src, community, pdu) for handler in self._handlers: # handler returns False/None. If other handlers may run # return False. Return True if handled, and no further processing required. if handler(tr): break
def handle_read(self): ip = struct.unpack("!I", self.recv(4))[0] # network byte-order port = struct.unpack("!H", self.recv(2))[0] # network byte-order length = struct.unpack("i", self.recv(4))[0] # host byte-order src = IpAddress(ip) src.port = port msg = self.recv(length) assert length == len(msg) tlv = BER_decode.get_tlv(msg) # should be community based message version, community, pdu = tlv.decode() if version == 0: pdu = _translate2v2(ip, community, pdu) arglist = (now(), src, community, pdu) for handler in self._handlers: # handler returns False/None if other handlers may run, # returns True if handled, and no further processing required. if handler(*arglist): break
def _decode_message(self, message): tlv = BER_decode.get_tlv(message) version, community, pdu = tlv.decode() return CommunityBasedMessage(community, pdu, version)
def decode(self): from pycopia.SNMP import BER_decode tlv = BER_decode.get_tlv(self.tostring()) return tlv.decode()