def encode_name(self,name): """ Encode label and store at end of buffer (compressing cached elements where needed) and store elements in 'names' dict """ if not isinstance(name,DNSLabel): name = DNSLabel(name) if len(name) > 253: raise DNSLabelError("Domain label too long: %r" % name) name = list(name.label) while name: if tuple(name) in self.names: # Cached - set pointer pointer = self.names[tuple(name)] pointer = set_bits(pointer,3,14,2) self.pack("!H",pointer) return else: self.names[tuple(name)] = self.offset element = name.pop(0) if len(element) > 63: raise DNSLabelError("Label component too long: %r" % element) self.pack("!B",len(element)) self.append(element) self.append(b'\x00')
def set_rcode(self, val): self.bitmap = set_bits(self.bitmap, val, 0, 4)
def set_ra(self, val): self.bitmap = set_bits(self.bitmap, val, 7)
def set_rd(self, val): self.bitmap = set_bits(self.bitmap, val, 8)
def set_tc(self, val): self.bitmap = set_bits(self.bitmap, val, 9)
def set_aa(self, val): self.bitmap = set_bits(self.bitmap, val, 10)
def set_opcode(self, val): self.bitmap = set_bits(self.bitmap, val, 11, 4)
def set_qr(self, val): self.bitmap = set_bits(self.bitmap, val, 15)
def set_rcode(self,val): self.bitmap = set_bits(self.bitmap,val,0,4)
def set_ra(self,val): self.bitmap = set_bits(self.bitmap,val,7)
def set_rd(self,val): self.bitmap = set_bits(self.bitmap,val,8)
def set_tc(self,val): self.bitmap = set_bits(self.bitmap,val,9)
def set_aa(self,val): self.bitmap = set_bits(self.bitmap,val,10)
def set_opcode(self,val): self.bitmap = set_bits(self.bitmap,val,11,4)
def set_qr(self,val): self.bitmap = set_bits(self.bitmap,val,15)