Class ldns_rdf

Class ldns_rdf

class ldns.ldns_rdf

Resource record data field.

The data is a network ordered array of bytes, which size is specified by the (16-bit) size field. To correctly parse it, use the type specified in the (16-bit) type field with a value from ldns_rdf_type.

absolute()

Checks whether the given dname string is absolute (i.e., ends with a ‘.’).

Returns:(bool) True or False

Note

This method was malfunctioning in ldns-1.3.16 and also possibly earlier.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname to use the method.

address_reverse()

Reverses an rdf, only actually useful for AAAA and A records.

The returned rdf has the type LDNS_RDF_TYPE_DNAME!

Returns:(ldns_rdf) The reversed rdf (a newly created rdf).
cat(rd2)

Concatenates rd2 after this dname (rd2 is copied, this dname is modified).

Parameters:rd2 (ldns_rdf) – The right-hand side.
Throws TypeError:
 When rd2 of non-ldns_rdf or non-ldns_dname type.
Returns:(ldns_status) LDNS_STATUS_OK on success.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

cat_clone(rd2)

Concatenates two dnames together.

Parameters:rd2 (ldns_rdf) – The right-hand side.
Throws TypeError:
 When rd2 of non-ldns_rdf or non-ldns_dname type.
Returns:(ldns_rdf) A new rdf with left-hand side + right-hand side content None when error.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

clone()

Clones a rdf structure.

The data are copied.

Returns:(ldns_rdf) A new rdf structure.
data()

Returns the data of the rdf.

Returns:(uint8_t *) uint8_t* pointer to the rdf’s data.
data_as_bytearray()

Returns the data of the rdf as a bytearray.

Returns:(bytearray) Bytearray containing the rdf data.
dname_compare(other)

Compares two dname rdf according to the algorithm for ordering in RFC4034 Section 6.

Parameters:other (ldns_rdf) – The second dname rdf to compare.
Throws TypeError:
 When not a ldns_rdf used.
Throws Exception:
 When not dnames compared.
Returns:(int) -1, 0 or 1 if self comes before other, self is equal or self comes after other respectively.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

static dname_new_frm_str(string)

Creates a new dname rdf instance from a given string.

This static method is equivalent to using of default ldns_rdf constructor.

Parameters:string (string) – String to use.
Throws TypeError:
 When not a string used.
Returns:ldns_rdf or None if error.

Warning

It is scheduled to be deprecated and removed. Use ldns_dname constructor instead.

get_type()

Returns the type of the rdf.

We need to prepend the prefix get_ here to prevent conflict with the rdf_type TYPE.

Returns:(ldns_rdf_type) Identifier of the type.
get_type_str()

Returns the type of the rdf as a human readable string.

Returns:String containing rdf type.
interval(middle, next)

Check whether the middle lays in the interval defined by this and next (this <= middle < next).

This method is useful for nsec checking

Parameters:
Throws TypeError:
 

When middle or next of non-ldns_rdf type.

Throws Exception:
 

When non-dname rdfs compared.

Returns:

(int) 0 on error or unknown, -1 when middle is in the interval, 1 when not.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

is_subdomain(parent)

Tests whether the name of the given instance falls under parent (i.e., is a sub-domain of parent).

This function will return False if the given dnames are equal.

Parameters:parent (ldns_rdf) – The parent’s name.
Throws TypeError:
 When parent of non-ldns_rdf type.
Returns:(bool) True if this falls under parent, otherwise False.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

label(labelpos)

Look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label.

The labels are numbered starting from 0 (left most).

Parameters:labelpos (integer) – Index of the label. (Labels are numbered 0, which is the left most.)
Throws TypeError:
 When labelpos of non-integer type.
Returns:(ldns_rdf) A new rdf with the label as name or None on error.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

label_count()

Count the number of labels inside a LDNS_RDF_DNAME type rdf.

Returns:(uint8_t) The number of labels. Will return 0 if not a dname.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

left_chop()

Chop one label off the left side of a dname.

(e.g., wwww.nlnetlabs.nl, becomes nlnetlabs.nl)

Returns:(ldns_rdf) The remaining dname or None when error.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

make_canonical()

Put a dname into canonical format (i.e., convert to lower case).

Performs no action if not a dname.

Warning

This method is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname to use the method.

static new_frm_str(string, rr_type, raiseException=True)

Creates a new rdf from a string of a given type.

Parameters:
  • string (string) – string to use
  • rr_type (integer) – The type of the rdf. See predefined RDF_TYPE_ constants.
  • raiseException (bool) – If True, an exception occurs in case a RDF object can’t be created.
Throws TypeError:
 

When parameters of mismatching types.

Throws Exception:
 

When raiseException set and rdf couldn’t be created.

Returns:

ldns_rdf object or None. If the object can’t be created and raiseException is True, an exception occurs.

Usage

>>> rdf = ldns.ldns_rdf.new_frm_str("74.125.43.99", ldns.LDNS_RDF_TYPE_A)
>>> print rdf, rdf.get_type_str()
A 74.125.43.99
>>> name = ldns.ldns_resolver.new_frm_file().get_name_by_addr(rdf)
>>> if (name): print name
99.43.125.74.in-addr.arpa.       85277   IN      PTR     bw-in-f99.google.com.
print_to_file(output)

Prints the data in the rdata field to the given output file stream (in presentation format).

reverse()

Returns a clone of the given dname with the labels reversed.

When reversing non-dnames a ”.” (root name) dname is returned.

Throws Exception:
 When used on non-dname rdfs.
Returns:(ldns_rdf) Clone of the dname with the labels reversed or ”.”.

Warning

It is scheduled to be deprecated and removed. Convert ldns_rdf to ldns_dname.

set_data(data)

Sets the data portion of the rdf.

The data are not copied, but are assigned to the rdf, data are decoupled from the Python engine.

Parameters:data (void *) – Data to be set.
set_size(size)

Sets the size of the rdf.

Parameters:size (integer) – The new size.
Throws TypeError:
 When size of non-integer type.
set_type(atype)

Sets the type of the rdf.

Parameters:atype (integer) – rdf type
Throws TypeError:
 When atype of non-integer type.
size()

Returns the size of the rdf.

Returns:(size_t) uint16_t with the size.
write_to_buffer(buffer)

Copies the rdata data to the buffer in wire format.

Parameters:buffer – Buffer to append the rdf to.
Throws TypeError:
 When buffer of non-ldns_buffer type.
Returns:(ldns_status) ldns_status
write_to_buffer_canonical(buffer)

Copies the rdata data to the buffer in wire format. If the rdata is a dname, the letters will be converted to lower case during the conversion.

Parameters:buffer (ldns_buffer) – LDNS buffer.
Throws TypeError:
 When buffer of non-ldns_buffer type.
Returns:(ldns_status) ldns_status

Predefined constants

RDF TYPE
  • LDNS_RDF_TYPE_NONE,
  • LDNS_RDF_TYPE_DNAME,
  • LDNS_RDF_TYPE_INT8,
  • LDNS_RDF_TYPE_INT16,
  • LDNS_RDF_TYPE_INT32,
  • LDNS_RDF_TYPE_A,
  • LDNS_RDF_TYPE_AAAA,
  • LDNS_RDF_TYPE_STR,
  • LDNS_RDF_TYPE_APL,
  • LDNS_RDF_TYPE_B32_EXT,
  • LDNS_RDF_TYPE_B64,
  • LDNS_RDF_TYPE_HEX,
  • LDNS_RDF_TYPE_NSEC,
  • LDNS_RDF_TYPE_TYPE,
  • LDNS_RDF_TYPE_CLASS,
  • LDNS_RDF_TYPE_CERT_ALG,
  • LDNS_RDF_TYPE_ALG,
  • LDNS_RDF_TYPE_UNKNOWN,
  • LDNS_RDF_TYPE_TIME,
  • LDNS_RDF_TYPE_PERIOD,
  • LDNS_RDF_TYPE_TSIGTIME,
  • LDNS_RDF_TYPE_HIP,
  • LDNS_RDF_TYPE_INT16_DATA,
  • LDNS_RDF_TYPE_SERVICE,
  • LDNS_RDF_TYPE_LOC,
  • LDNS_RDF_TYPE_WKS,
  • LDNS_RDF_TYPE_NSAP,
  • LDNS_RDF_TYPE_IPSECKEY,
  • LDNS_RDF_TYPE_NSEC3_SALT,
  • LDNS_RDF_TYPE_NSEC3_NEXT_OWNER

Table Of Contents

Previous topic

Class ldns_rr

Next topic

Class ldns_dname