Class ldns_rr

Class ldns_rr

class ldns.ldns_rr

Resource Record (RR).

The RR is the basic DNS element that contains actual data. This class allows to create RR and manipulate with the content.

Use ldns_rr_new(), ldns_rr_new_frm_type(), new_frm_fp(), new_frm_fp_l(), new_frm_str() or new_question_frm_str() to create ldns_rr instances.

a_address()

Returns the address rdf of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA rr.

Returns:(ldns_rdf) with the address or None on failure.
a_set_address(f)

Sets the address of a LDNS_RR_TYPE_A or LDNS_RR_TYPE_AAAA rr.

Parameters:f (ldns_rdf) – The address to be set.
Throws TypeError:
 When f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
static class_by_name(string)

Retrieves a class identifier value by looking up its name.

Parameters:string (str) – Class name.
Throws TypeError:
 when string of inappropriate type.
Returns:(int) Class identifier value, or 0 if not valid class name given.
clone()

Clones a rr and all its data.

Returns:(ldns_rr) The new rr or None on failure.
compare_ds(rr2)

Returns True if the given rr’s are equal.

Also returns True if one record is a DS that represents the same DNSKEY record as the other record.

Parameters:rr2 (ldns_rr) – The second rr.
Throws TypeError:
 When rr2 of non-ldns_rr type.
Returns:(bool) True if equal otherwise False.
compare_no_rdata(rr2)

Compares two rrs, up to the rdata.

Parameters:rr2 (ldns_rr) – Rhe second rr.
Throws TypeError:
 When rr2 of non-ldns_rr type.
Returns:(int) 0 if equal, negative integer if self comes before rr2, positive integer if rr2 comes before self.
dnskey_algorithm()

Returns the algorithm of a LDNS_RR_TYPE_DNSKEY rr.

Returns:(ldns_rdf) with the algorithm or None on failure.
dnskey_flags()

Returns the flags of a LDNS_RR_TYPE_DNSKEY rr.

Returns:(ldns_rdf) with the flags or None on failure.
dnskey_key()

Returns the key data of a LDNS_RR_TYPE_DNSKEY rr.

Returns:(ldns_rdf) with the key data or None on failure.
dnskey_key_size()

Get the length of the keydata in bits.

Returns:(size_t) the keysize in bits.
static dnskey_key_size_raw(keydata, len, alg)

Get the length of the keydata in bits.

Parameters:
  • keydata (unsigned char *) – Key raw data.
  • len (size_t) – Number of bytes of keydata.
  • alg (ldns_algorithm) – Algorithm identifier.
Returns:

(size_t) The length of key data in bits.

dnskey_protocol()

Returns the protocol of a LDNS_RR_TYPE_DNSKEY rr.

Returns:(ldns_rdf) with the protocol or None on failure.
dnskey_set_algorithm(f)

Sets the algorithm of a LDNS_RR_TYPE_DNSKEY rr

Parameters:f (ldns_rdf) – The algorithm to set.
Throws TypeError:
 When f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
dnskey_set_flags(f)

Sets the flags of a LDNS_RR_TYPE_DNSKEY rr.

Parameters:f (ldns_rdf) – The flags to be set.
Throws TypeError:
 When f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
dnskey_set_key(f)

Sets the key data of a LDNS_RR_TYPE_DNSKEY rr.

Parameters:f (ldns_rdf) – The key data to set.
Throws TypeError:
 When f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
dnskey_set_protocol(f)

Sets the protocol of a LDNS_RR_TYPE_DNSKEY rr.

Parameters:f (ldns_rdf) – The protocol to set.
Throws TypeError:
 When f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
get_class()

Returns the class of the rr.

Returns:(int) The class identifier of the rr.
get_class_str()

Converts an RR class value to its string representation, and returns that string.

Returns:(str) containing class identification.
get_type()

Returns the type of the rr.

Returns:(int) The type identifier of the rr.
get_type_str()

Converts an RR type value to its string representation, and returns that string.

Returns:(str) containing type identification.
is_question()

Returns the question flag of a rr structure.

Returns:(bool) True if question flag is set.
label_count()

Counts the number of labels of the owner name.

Returns:(int) The number of labels.
mx_exchange()

Returns the mx host of a LDNS_RR_TYPE_MX rr.

Returns:(ldns_rdf) with the name of the MX host or None on failure.
mx_preference()

Returns the mx preference of a LDNS_RR_TYPE_MX rr.

Returns:(ldns_rdf) with the preference or None on failure.
static new_frm_fp(file, default_ttl=0, origin=None, prev=None, raiseException=True)

Creates a new rr from a file containing a string.

Parameters:
  • file – Opened file.
  • default_ttl (int) – If 0 DEF_TTL will be used.
  • origin (ldns_dname) – When the owner is relative add this.
  • prev (ldns_rdf) – When the owner is white spaces use this.
  • raiseException – If True, an exception occurs in case a resolver object can’t be created.
Throws Exception:
 

If raiseException is set and the input cannot be read.

Throws TypeError:
 

When parameters of incorrect types.

Returns:

None when fails, otherwise a tuple containing:

  • rr - (ldns_rr) RR object or None. If the object can’t be created and raiseException is True, an exception occurs.
  • ttl - (int) None or TTL if the file contains a TTL directive.
  • origin - (ldns_rdf) None or dname rdf if the file contains a ORIGIN directive.
  • prev - (ldns_rdf) None or updated value of prev parameter.

Note

The type checking of origin is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.

static new_frm_fp_l(file, default_ttl=0, origin=None, prev=None, raiseException=True)

Creates a new rr from a file containing a string.

Parameters:
  • file – Opened file.
  • default_ttl (int) – If 0 DEF_TTL will be used.
  • origin (ldns_dname) – When the owner is relative add this.
  • prev (ldns_rdf) – When the owner is white spaces use this.
  • raiseException – Iif True, an exception occurs in case a resolver object can’t be created.
Throws Exception:
 

If raiseException is set and the input cannot be read.

Throws TypeError:
 

When parameters of incorrect types.

Returns:

None when fails, otherwise a tuple containing:

  • rr - (ldns_rr) RR object or None. If the object can’t be created and raiseException is True, an exception occurs.
  • line - (int) line number (for debugging).
  • ttl - (int) None or TTL if the file contains a TTL directive .
  • origin - (ldns_rdf) None or dname rdf if the file contains a ORIGIN directive.
  • prev - (ldns_rdf) None or updated value of prev parameter.

Note

The type checking of origin is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.

static new_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True)

Creates an rr object from a string.

The string should be a fully filled-in rr, like “owner_name [space] TTL [space] CLASS [space] TYPE [space] RDATA.”

Parameters:
  • string (str) – The string to convert.
  • default_ttl (int) – Default ttl value for the rr. If 0 DEF_TTL will be used.
  • origin (ldns_dname) – When the owner is relative add this.
  • prev (ldns_rdf) – The previous owner name.
  • raiseException – If True, an exception occurs in case a rr instance can’t be created.
Throws Exception:
 

If raiseExceprion is set and fails.

Throws TypeError:
 

When parameters of incorrect types.

Returns:

(ldns_rr) RR instance or None.

Note

The type checking of origin is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.

Usage

>>> import ldns
>>> rr = ldns.ldns_rr.new_frm_str("www.nic.cz. IN A 192.168.1.1", 300)
>>> print rr
www.nic.cz.  300  IN  A  192.168.1.1
>>> rr = ldns.ldns_rr.new_frm_str("test.nic.cz. 600 IN A 192.168.1.2")
>>> print rr
test.nic.cz.  600  IN  A  192.168.1.2
static new_frm_str_prev(string, default_ttl=0, origin=None, prev=None, raiseException=True)

Creates an rr object from a string.

The string should be a fully filled-in rr, like “owner_name [space] TTL [space] CLASS [space] TYPE [space] RDATA”.

Parameters:
  • string (str) – The string to convert.
  • default_ttl (int) – Default ttl value for the rr. If 0 DEF_TTL will be used.
  • origin (ldns_dname) – When the owner is relative add this.
  • prev (ldns_rdf) – The previous owner name.
  • raiseException – If True, an exception occurs in case when a rr instance can’t be created.
Throws Exception:
 

If raiseExceprion is set and fails.

Throws TypeError:
 

When parameters of incorrect types.

Returns:

None when fails, otherwise a tuple containing:

  • rr - (ldns_rr) RR instance or None. If the object can’t be created and raiseException is True, an exception occurs.
  • prev - (ldns_rdf) Owner name found in this string or None.

Note

The type checking of origin is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.

static new_question_frm_str(string, default_ttl=0, origin=None, prev=None, raiseException=True)

Creates an rr object from a string.

The string is like new_frm_str() but without rdata.

Parameters:
  • string (str) – The string to convert.
  • origin (ldns_dname) – When the owner is relative add this.
  • prev (ldns_rdf) – The previous owner name.
  • raiseException – If True, an exception occurs in case a rr instance can’t be created.
Throws Exception:
 

If raiseExceprion is set and fails.

Throws TypeError:
 

When parameters of incorrect types.

Returns:

(ldns_rr) RR instance or None. If the object can’t be created and raiseException is True, an exception occurs.

Note

The type checking of origin is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.

ns_nsdname()

Returns the name of a LDNS_RR_TYPE_NS rr.

Returns:(ldns_rdf) A dname rdf with the name or None on failure.
owner()

Returns the owner name of an rr structure.

Returns:(ldns_dname) Owner name or None on failure.
pop_rdf()

Removes a rd_field member, it will be popped from the last position.

Returns:(ldns_rdf) rdf which was popped, None if nothing.
print_to_file(output)

Prints the data in the resource record to the given file stream (in presentation format).

Parameters:output – Opened file stream.
Throws TypeError:
 When output not a file.
push_rdf(f)

Sets rd_field member, it will be placed in the next available spot.

Parameters:f (ldns_rdf) – The rdf to be appended.
Throws TypeError:
 When f of non-ldns_rdf type.
Returns:(bool) Returns True if success, False otherwise.
rd_count()

Returns the rd_count of an rr structure.

Returns:(size_t) the rd count of the rr.
rdf(nr)

Returns the rdata field with the given index.

Parameters:nr (positive int) – The index of the rdf to return.
Throws TypeError:
 When nr not a positive integer.
Returns:(ldns_rdf) The given rdf or None if fails.
rdfs()

Returns a generator object of rdata records.

Returns:Generator of ldns_rdf.
rrsig_algorithm()

Returns the algorithm identifier of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the algorithm or None on failure.
rrsig_expiration()

Returns the expiration time of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the expiration time or None on failure.
rrsig_inception()

Returns the inception time of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the inception time or None on failure.
rrsig_keytag()

Returns the keytag of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the keytag or None on failure.
rrsig_labels()

Returns the number of labels of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the number of labels or None on failure.
rrsig_origttl()

Returns the original TTL of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the original TTL or None on failure.
rrsig_set_algorithm(f)

Sets the algorithm of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The algorithm to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_expiration(f)

Sets the expireation date of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The expireation date to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_inception(f)

Sets the inception date of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The inception date to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_keytag(f)

Sets the keytag of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The keytag to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_labels(f)

Sets the number of labels of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The number of labels to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_origttl(f)

Sets the original TTL of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The original TTL to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_sig(f)

Sets the signature data of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The signature data to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_signame(f)

Sets the signers name of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The signers name to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_set_typecovered(f)

Sets the typecovered of a LDNS_RR_TYPE_RRSIG rr.

Parameters:f (ldns_rdf) – The type covered to set.
Throws TypeError:
 when f of non-ldns_rdf type.
Returns:(bool) True on success, False otherwise.
rrsig_sig()

Returns the signature data of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the signature data or None on failure.
rrsig_signame()

Returns the signers name of a LDNS_RR_TYPE_RRSIG RR.

Returns:(ldns_rdf) with the signers name or None on failure.
rrsig_typecovered()

Returns the type covered of a LDNS_RR_TYPE_RRSIG rr.

Returns:(ldns_rdf) with the type covered or None on failure.
set_class(rr_class)

Sets the class in the rr.

Parameters:rr_class (int) – Set to this class.
Throws TypeError:
 when rr_class of non-integer type.
set_owner(owner)

Sets the owner in the rr structure.

Parameters:owner (ldns_dname) – Owner name.
Throws TypeError:
 when owner of non-ldns_dname type.

Note

The type checking of owner is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.

set_question(question)

Sets the question flag in the rr structure.

Parameters:question (bool) – Question flag.
set_rd_count(count)

Sets the rd_count in the rr.

Parameters:count (positive int) – Set to this count.
Throws TypeError:
 when count of non-integer type.
set_rdf(f, position)

Sets a rdf member, it will be set on the position given.

The old value is returned, like pop.

Parameters:
  • f (ldns_rdf) – The rdf to be set.
  • position (positive int) – The position the set the rdf.
Throws TypeError:
 

when mismatching types passed.

Returns:

(ldns_rdf) the old value in the rr, None on failure.

set_ttl(ttl)

Sets the ttl in the rr structure.

Parameters:ttl (positive int) – Set to this ttl.
Throws TypeError:
 when ttl of non-integer type.
set_type(rr_type)

Sets the type in the rr.

Parameters:rr_type (ineteger) – Set to this type.
Throws TypeError:
 when rr_type of non-integer type.
to_canonical()

Converts each dname in a rr to its canonical form.

ttl()

Returns the ttl of an rr structure.

Returns:(int) the ttl of the rr.
static type_by_name(string)

Retrieves a rr type identifier value by looking up its name.

Returns 0 if invalid name passed.

Parameters:string (str) – RR type name.
Throws TypeError:
 when string of inappropriate type.
Returns:(int) RR type identifier, or 0 if no matching value to identifier found.
uncompressed_size()

Calculates the uncompressed size of an RR.

Returns:(inetger) size of the rr.
write_data_to_buffer(buffer)

Converts an rr’s rdata to wire format, while excluding the owner name and all the stuff before the rdata.

This is needed in DNSSEC key-tag calculation, the ds calculation from the key and maybe elsewhere.

Parameters:buffer (ldns_buffer) – Buffer to append the result to.
Throws TypeError:
 when buffer of non-ldns_buffer type.
Returns:(ldns_status) ldns_status
write_rrsig_to_buffer(buffer)

Converts a rrsig to wire format BUT EXCLUDE the rrsig rdata.

This is needed in DNSSEC verification.

Parameters:buffer (ldns_buffer) – Buffer to append the result to.
Throws TypeError:
 when buffer of non-ldns_buffer type.
Returns:(ldns_status) ldns_status
write_to_buffer(buffer, section)

Copies the rr data to the buffer in wire format.

Parameters:
  • buffer (ldns_buffer) – Buffer to append the result to.
  • section (int) – The section in the packet this rr is supposed to be in (to determine whether to add rdata or not).
Throws TypeError:
 

when arguments of mismatching types passed.

Returns:

(ldns_status) ldns_status

write_to_buffer_canonical(buffer, section)

Copies the rr data to the buffer in wire format, in canonical format according to RFC3597 (every dname in rdata fields of RR’s mentioned in that RFC will be converted to lower-case).

Parameters:
  • buffer (ldns_buffer) – Buffer to append the result to.
  • section (int) – The section in the packet this rr is supposed to be in (to determine whether to add rdata or not).
Throws TypeError:
 

when arguments of mismatching types passed.

Returns:

(ldns_status) ldns_status

Class ldns_rr_descriptor

class ldns.ldns_rr_descriptor(rr_type)

Resource Record descriptor.

This structure contains, for all rr types, the rdata fields that are defined.

In order to create a class instance use ldns_rr_descriptor().

field_type(field)

Returns the rdf type for the given rdata field number of the rr type for the given descriptor.

Parameters:field (positive int) – The field number.
Throws TypeError:
 when field of non-inetger type.
Returns:(int) the rdf type for the field.
static ldns_rr_descriptor(rr_type)

Returns the resource record descriptor for the given type.

Parameters:rr_type (int) – RR type.
Throws TypeError:
 when rr_type of inappropriate type.
Returns:(ldns_rr_descriptor) RR descriptor class.
maximum()

Returns the maximum number of rdata fields of the rr type this descriptor describes.

Returns:(int) the maximum number of rdata fields.
minimum()

Returns the minimum number of rdata fields of the rr type this descriptor describes.

Returns:(int) the minimum number of rdata fields.

Table Of Contents

Previous topic

Class ldns_pkt

Next topic

Class ldns_rdf