def from_wire(rdclass, rdtype, wire, current, rdlen, origin=None): """Build an rdata object from wire format This function attempts to dynamically load a class which implements the specified rdata class and type. If there is no class-and-type-specific implementation, the GenericRdata class is used. Once a class is chosen, its from_wire() class method is called with the parameters to this function. @param rdclass: The rdata class @type rdclass: int @param rdtype: The rdata type @type rdtype: int @param wire: The wire-format message @type wire: string @param current: The offet in wire of the beginning of the rdata. @type current: int @param rdlen: The length of the wire-format rdata @type rdlen: int @param origin: The origin to use for relative names @type origin: name.Name @rtype: rdata.Rdata instance""" wire = wiredata.maybe_wrap(wire) cls = get_rdata_class(rdclass, rdtype) return cls.from_wire(rdclass, rdtype, wire, current, rdlen, origin)
def __init__(self, wire, message, question_only=False, one_rr_per_rrset=False, ignore_trailing=False): self.wire = wiredata.maybe_wrap(wire) self.message = message self.current = 0 self.updating = False self.zone_rdclass = rdataclass.IN self.question_only = question_only self.one_rr_per_rrset = one_rr_per_rrset self.ignore_trailing = ignore_trailing
def from_wire(message, current): """Convert possibly compressed wire format into a Name. @param message: the entire DNS message @type message: string @param current: the offset of the beginning of the name from the start of the message @type current: int @raises name.BadPointer: a compression pointer did not point backwards in the message @raises name.BadLabelType: an invalid label type was encountered. @returns: a tuple consisting of the name that was read and the number of bytes of the wire format message which were consumed reading it @rtype: (name.Name object, int) tuple """ if not isinstance(message, str): raise ValueError("input to from_wire() must be a byte string") message = wiredata.maybe_wrap(message) labels = [] biggest_pointer = current hops = 0 count = ord(message[current]) current += 1 cused = 1 while count != 0: if count < 64: labels.append(message[current : current + count].unwrap()) current += count if hops == 0: cused += count elif count >= 192: current = (count & 0x3f) * 256 + ord(message[current]) if hops == 0: cused += 1 if current >= biggest_pointer: raise BadPointer biggest_pointer = current hops += 1 else: raise BadLabelType count = ord(message[current]) current += 1 if hops == 0: cused += 1 labels.append('') return (Name(labels), cused)
def from_wire(message, current): """Convert possibly compressed wire format into a Name. @param message: the entire DNS message @type message: string @param current: the offset of the beginning of the name from the start of the message @type current: int @raises name.BadPointer: a compression pointer did not point backwards in the message @raises name.BadLabelType: an invalid label type was encountered. @returns: a tuple consisting of the name that was read and the number of bytes of the wire format message which were consumed reading it @rtype: (name.Name object, int) tuple """ if not isinstance(message, str): raise ValueError("input to from_wire() must be a byte string") message = wiredata.maybe_wrap(message) labels = [] biggest_pointer = current hops = 0 count = ord(message[current]) current += 1 cused = 1 while count != 0: if count < 64: labels.append(message[current:current + count].unwrap()) current += count if hops == 0: cused += count elif count >= 192: current = (count & 0x3f) * 256 + ord(message[current]) if hops == 0: cused += 1 if current >= biggest_pointer: raise BadPointer biggest_pointer = current hops += 1 else: raise BadLabelType count = ord(message[current]) current += 1 if hops == 0: cused += 1 labels.append('') return (Name(labels), cused)