Пример #1
0
 def encode(self, names, offset):
     ret = ""
     for e in self.rtype[2]:
         d = self.rdata[e[1]]
         if e[2] == "strc":
             ret += d
             offset += len(d)
         if e[2] == "cmdn":
             buf, names = proto.encodename(d, names, offset)
             ret += buf
             offset += len(buf)
         if e[2] == "lstr":
             ret += chr(len(d)) + d
             offset += 1 + len(d)
         if e[2] == "llstr":
             ret += struct.pack(">H", len(d)) + d
             offset += struct.calcsize(">H") + len(d)
         if e[2] == "short":
             ret += struct.pack(">H", d)
             offset += struct.calcsize(">H")
         if e[2] == "long":
             ret += struct.pack(">L", d)
             offset += struct.calcsize(">L")
         if e[2] == "int6":
             ret += struct.pack(">Q", d)[-6:]
             offset += 6
     return ret, names
Пример #2
0
 def encode(self, names, offset):
     ret, names = proto.encodename(self.name, names, offset)
     ret += struct.pack(">HH", self.rtype, self.rclass)
     return ret, names