示例#1
0
文件: rec.py 项目: dolda2000/ldd
 def decode(self, rtid, packet, offset, dlen):
     rtype = rtypebyid(rtid)
     origoff = offset
     rdata = {}
     if rtype is None:
         rtype = (rtid, "Unknown", [("s", "unknown", "strc", dlen)])
     for e in rtype[2]:
         if e[2] == "strc":
             d = packet[offset:offset + e[3]]
             offset += e[3]
         if e[2] == "cmdn":
             d, offset = proto.decodename(packet, offset)
         if e[2] == "lstr":
             dl = ord(packet[offset])
             offset += 1
             d = packet[offset:offset + dl]
             offset += dl
         if e[2] == "llstr":
             (dl,) = struct.unpack(">H", packet[offset:offset + struct.calcsize(">H")])
             offset += struct.calcsize(">H")
             d = packet[offset:offset + dl]
             offset += dl
         if e[2] == "short":
             (d,) = struct.unpack(">H", packet[offset:offset + struct.calcsize(">H")])
             offset += struct.calcsize(">H")
         if e[2] == "long":
             (d,) = struct.unpack(">L", packet[offset:offset + struct.calcsize(">L")])
             offset += struct.calcsize(">L")
         if e[2] == "int6":
             (d,) = struct.unpack(">Q", ("\0" * (struct.calcsize(">Q") - 6)) + packet[offset:offset + 6])
             offset += 6
         rdata[e[1]] = d
     if origoff + dlen != offset:
         raise malformedrr(rtype[1] + " RR data length mismatch")
     return rrdata(rtype, rdata)
示例#2
0
文件: rec.py 项目: dolda2000/ldd
 def decode(self, packet, offset):
     name, offset = proto.decodename(packet, offset)
     rtype, rclass = struct.unpack(">HH", packet[offset:offset + struct.calcsize(">HH")])
     offset += struct.calcsize(">HH")
     ret = rrhead(name, rtype, rclass)
     return ret, offset