wire2host.h File Reference

Contains functions that translate dns data from the wire format (as sent by servers and clients) to the internal structures. More...

Go to the source code of this file.

Defines

#define LDNS_HEADER_SIZE   12
#define LDNS_RD_MASK   0x01U
#define LDNS_RD_SHIFT   0
#define LDNS_RD_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_RD_MASK)
#define LDNS_RD_SET(wirebuf)   (*(wirebuf+2) |= LDNS_RD_MASK)
#define LDNS_RD_CLR(wirebuf)   (*(wirebuf+2) &= ~LDNS_RD_MASK)
#define LDNS_TC_MASK   0x02U
#define LDNS_TC_SHIFT   1
#define LDNS_TC_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_TC_MASK)
#define LDNS_TC_SET(wirebuf)   (*(wirebuf+2) |= LDNS_TC_MASK)
#define LDNS_TC_CLR(wirebuf)   (*(wirebuf+2) &= ~LDNS_TC_MASK)
#define LDNS_AA_MASK   0x04U
#define LDNS_AA_SHIFT   2
#define LDNS_AA_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_AA_MASK)
#define LDNS_AA_SET(wirebuf)   (*(wirebuf+2) |= LDNS_AA_MASK)
#define LDNS_AA_CLR(wirebuf)   (*(wirebuf+2) &= ~LDNS_AA_MASK)
#define LDNS_OPCODE_MASK   0x78U
#define LDNS_OPCODE_SHIFT   3
#define LDNS_OPCODE_WIRE(wirebuf)   ((*(wirebuf+2) & LDNS_OPCODE_MASK) >> LDNS_OPCODE_SHIFT)
#define LDNS_OPCODE_SET(wirebuf, opcode)   (*(wirebuf+2) = ((*(wirebuf+2)) & ~LDNS_OPCODE_MASK) | ((opcode) << LDNS_OPCODE_SHIFT))
#define LDNS_QR_MASK   0x80U
#define LDNS_QR_SHIFT   7
#define LDNS_QR_WIRE(wirebuf)   (*(wirebuf+2) & LDNS_QR_MASK)
#define LDNS_QR_SET(wirebuf)   (*(wirebuf+2) |= LDNS_QR_MASK)
#define LDNS_QR_CLR(wirebuf)   (*(wirebuf+2) &= ~LDNS_QR_MASK)
#define LDNS_RCODE_MASK   0x0fU
#define LDNS_RCODE_SHIFT   0
#define LDNS_RCODE_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_RCODE_MASK)
#define LDNS_RCODE_SET(wirebuf, rcode)   (*(wirebuf+3) = ((*(wirebuf+3)) & ~LDNS_RCODE_MASK) | (rcode))
#define LDNS_CD_MASK   0x10U
#define LDNS_CD_SHIFT   4
#define LDNS_CD_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_CD_MASK)
#define LDNS_CD_SET(wirebuf)   (*(wirebuf+3) |= LDNS_CD_MASK)
#define LDNS_CD_CLR(wirebuf)   (*(wirebuf+3) &= ~LDNS_CD_MASK)
#define LDNS_AD_MASK   0x20U
#define LDNS_AD_SHIFT   5
#define LDNS_AD_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_AD_MASK)
#define LDNS_AD_SET(wirebuf)   (*(wirebuf+3) |= LDNS_AD_MASK)
#define LDNS_AD_CLR(wirebuf)   (*(wirebuf+3) &= ~LDNS_AD_MASK)
#define LDNS_Z_MASK   0x40U
#define LDNS_Z_SHIFT   6
#define LDNS_Z_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_Z_MASK)
#define LDNS_Z_SET(wirebuf)   (*(wirebuf+3) |= LDNS_Z_MASK)
#define LDNS_Z_CLR(wirebuf)   (*(wirebuf+3) &= ~LDNS_Z_MASK)
#define LDNS_RA_MASK   0x80U
#define LDNS_RA_SHIFT   7
#define LDNS_RA_WIRE(wirebuf)   (*(wirebuf+3) & LDNS_RA_MASK)
#define LDNS_RA_SET(wirebuf)   (*(wirebuf+3) |= LDNS_RA_MASK)
#define LDNS_RA_CLR(wirebuf)   (*(wirebuf+3) &= ~LDNS_RA_MASK)
#define LDNS_ID_WIRE(wirebuf)   (ldns_read_uint16(wirebuf))
#define LDNS_ID_SET(wirebuf, id)   (ldns_write_uint16(wirebuf, id))
#define LDNS_QDCOUNT_OFF   4
#define LDNS_QDCOUNT(wirebuf)   (ldns_read_uint16(wirebuf+LDNS_QDCOUNT_OFF))
#define LDNS_ANCOUNT_OFF   6
#define LDNS_ANCOUNT(wirebuf)   (ldns_read_uint16(wirebuf+LDNS_ANCOUNT_OFF))
#define LDNS_NSCOUNT_OFF   8
#define LDNS_NSCOUNT(wirebuf)   (ldns_read_uint16(wirebuf+LDNS_NSCOUNT_OFF))
#define LDNS_ARCOUNT_OFF   10
#define LDNS_ARCOUNT(wirebuf)   (ldns_read_uint16(wirebuf+LDNS_ARCOUNT_OFF))

Functions

ldns_status ldns_wire2pkt (ldns_pkt **packet, const uint8_t *data, size_t len)
 converts the data on the uint8_t bytearray (in wire format) to a DNS packet.
ldns_status ldns_buffer2pkt_wire (ldns_pkt **packet, ldns_buffer *buffer)
 converts the data on the uint8_t bytearray (in wire format) to a DNS packet.
ldns_status ldns_wire2dname (ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
 converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.
ldns_status ldns_wire2rdf (ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos)
 converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the list of rdfs of the given rr.
ldns_status ldns_wire2rr (ldns_rr **rr, const uint8_t *wire, size_t max, size_t *pos, ldns_pkt_section section)
 converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.


Detailed Description

Contains functions that translate dns data from the wire format (as sent by servers and clients) to the internal structures.

Definition in file wire2host.h.


Define Documentation

#define LDNS_HEADER_SIZE   12

Definition at line 32 of file wire2host.h.

#define LDNS_RD_MASK   0x01U

Definition at line 35 of file wire2host.h.

#define LDNS_RD_SHIFT   0

Definition at line 36 of file wire2host.h.

#define LDNS_RD_WIRE ( wirebuf   )     (*(wirebuf+2) & LDNS_RD_MASK)

Definition at line 37 of file wire2host.h.

#define LDNS_RD_SET ( wirebuf   )     (*(wirebuf+2) |= LDNS_RD_MASK)

Definition at line 38 of file wire2host.h.

#define LDNS_RD_CLR ( wirebuf   )     (*(wirebuf+2) &= ~LDNS_RD_MASK)

Definition at line 39 of file wire2host.h.

#define LDNS_TC_MASK   0x02U

Definition at line 41 of file wire2host.h.

#define LDNS_TC_SHIFT   1

Definition at line 42 of file wire2host.h.

#define LDNS_TC_WIRE ( wirebuf   )     (*(wirebuf+2) & LDNS_TC_MASK)

Definition at line 43 of file wire2host.h.

#define LDNS_TC_SET ( wirebuf   )     (*(wirebuf+2) |= LDNS_TC_MASK)

Definition at line 44 of file wire2host.h.

#define LDNS_TC_CLR ( wirebuf   )     (*(wirebuf+2) &= ~LDNS_TC_MASK)

Definition at line 45 of file wire2host.h.

#define LDNS_AA_MASK   0x04U

Definition at line 47 of file wire2host.h.

#define LDNS_AA_SHIFT   2

Definition at line 48 of file wire2host.h.

#define LDNS_AA_WIRE ( wirebuf   )     (*(wirebuf+2) & LDNS_AA_MASK)

Definition at line 49 of file wire2host.h.

#define LDNS_AA_SET ( wirebuf   )     (*(wirebuf+2) |= LDNS_AA_MASK)

Definition at line 50 of file wire2host.h.

#define LDNS_AA_CLR ( wirebuf   )     (*(wirebuf+2) &= ~LDNS_AA_MASK)

Definition at line 51 of file wire2host.h.

#define LDNS_OPCODE_MASK   0x78U

Definition at line 53 of file wire2host.h.

#define LDNS_OPCODE_SHIFT   3

Definition at line 54 of file wire2host.h.

#define LDNS_OPCODE_WIRE ( wirebuf   )     ((*(wirebuf+2) & LDNS_OPCODE_MASK) >> LDNS_OPCODE_SHIFT)

Definition at line 55 of file wire2host.h.

#define LDNS_OPCODE_SET ( wirebuf,
opcode   )     (*(wirebuf+2) = ((*(wirebuf+2)) & ~LDNS_OPCODE_MASK) | ((opcode) << LDNS_OPCODE_SHIFT))

Definition at line 56 of file wire2host.h.

#define LDNS_QR_MASK   0x80U

Definition at line 59 of file wire2host.h.

#define LDNS_QR_SHIFT   7

Definition at line 60 of file wire2host.h.

#define LDNS_QR_WIRE ( wirebuf   )     (*(wirebuf+2) & LDNS_QR_MASK)

Definition at line 61 of file wire2host.h.

#define LDNS_QR_SET ( wirebuf   )     (*(wirebuf+2) |= LDNS_QR_MASK)

Definition at line 62 of file wire2host.h.

#define LDNS_QR_CLR ( wirebuf   )     (*(wirebuf+2) &= ~LDNS_QR_MASK)

Definition at line 63 of file wire2host.h.

#define LDNS_RCODE_MASK   0x0fU

Definition at line 66 of file wire2host.h.

#define LDNS_RCODE_SHIFT   0

Definition at line 67 of file wire2host.h.

#define LDNS_RCODE_WIRE ( wirebuf   )     (*(wirebuf+3) & LDNS_RCODE_MASK)

Definition at line 68 of file wire2host.h.

#define LDNS_RCODE_SET ( wirebuf,
rcode   )     (*(wirebuf+3) = ((*(wirebuf+3)) & ~LDNS_RCODE_MASK) | (rcode))

Definition at line 69 of file wire2host.h.

#define LDNS_CD_MASK   0x10U

Definition at line 72 of file wire2host.h.

#define LDNS_CD_SHIFT   4

Definition at line 73 of file wire2host.h.

#define LDNS_CD_WIRE ( wirebuf   )     (*(wirebuf+3) & LDNS_CD_MASK)

Definition at line 74 of file wire2host.h.

#define LDNS_CD_SET ( wirebuf   )     (*(wirebuf+3) |= LDNS_CD_MASK)

Definition at line 75 of file wire2host.h.

#define LDNS_CD_CLR ( wirebuf   )     (*(wirebuf+3) &= ~LDNS_CD_MASK)

Definition at line 76 of file wire2host.h.

#define LDNS_AD_MASK   0x20U

Definition at line 78 of file wire2host.h.

#define LDNS_AD_SHIFT   5

Definition at line 79 of file wire2host.h.

#define LDNS_AD_WIRE ( wirebuf   )     (*(wirebuf+3) & LDNS_AD_MASK)

Definition at line 80 of file wire2host.h.

#define LDNS_AD_SET ( wirebuf   )     (*(wirebuf+3) |= LDNS_AD_MASK)

Definition at line 81 of file wire2host.h.

#define LDNS_AD_CLR ( wirebuf   )     (*(wirebuf+3) &= ~LDNS_AD_MASK)

Definition at line 82 of file wire2host.h.

#define LDNS_Z_MASK   0x40U

Definition at line 84 of file wire2host.h.

#define LDNS_Z_SHIFT   6

Definition at line 85 of file wire2host.h.

#define LDNS_Z_WIRE ( wirebuf   )     (*(wirebuf+3) & LDNS_Z_MASK)

Definition at line 86 of file wire2host.h.

#define LDNS_Z_SET ( wirebuf   )     (*(wirebuf+3) |= LDNS_Z_MASK)

Definition at line 87 of file wire2host.h.

#define LDNS_Z_CLR ( wirebuf   )     (*(wirebuf+3) &= ~LDNS_Z_MASK)

Definition at line 88 of file wire2host.h.

#define LDNS_RA_MASK   0x80U

Definition at line 90 of file wire2host.h.

#define LDNS_RA_SHIFT   7

Definition at line 91 of file wire2host.h.

#define LDNS_RA_WIRE ( wirebuf   )     (*(wirebuf+3) & LDNS_RA_MASK)

Definition at line 92 of file wire2host.h.

#define LDNS_RA_SET ( wirebuf   )     (*(wirebuf+3) |= LDNS_RA_MASK)

Definition at line 93 of file wire2host.h.

#define LDNS_RA_CLR ( wirebuf   )     (*(wirebuf+3) &= ~LDNS_RA_MASK)

Definition at line 94 of file wire2host.h.

#define LDNS_ID_WIRE ( wirebuf   )     (ldns_read_uint16(wirebuf))

Definition at line 97 of file wire2host.h.

#define LDNS_ID_SET ( wirebuf,
id   )     (ldns_write_uint16(wirebuf, id))

Definition at line 98 of file wire2host.h.

#define LDNS_QDCOUNT_OFF   4

Definition at line 101 of file wire2host.h.

#define LDNS_QDCOUNT ( wirebuf   )     (ldns_read_uint16(wirebuf+LDNS_QDCOUNT_OFF))

Definition at line 105 of file wire2host.h.

#define LDNS_ANCOUNT_OFF   6

Definition at line 108 of file wire2host.h.

#define LDNS_ANCOUNT ( wirebuf   )     (ldns_read_uint16(wirebuf+LDNS_ANCOUNT_OFF))

Definition at line 109 of file wire2host.h.

#define LDNS_NSCOUNT_OFF   8

Definition at line 112 of file wire2host.h.

#define LDNS_NSCOUNT ( wirebuf   )     (ldns_read_uint16(wirebuf+LDNS_NSCOUNT_OFF))

Definition at line 113 of file wire2host.h.

#define LDNS_ARCOUNT_OFF   10

Definition at line 116 of file wire2host.h.

#define LDNS_ARCOUNT ( wirebuf   )     (ldns_read_uint16(wirebuf+LDNS_ARCOUNT_OFF))

Definition at line 117 of file wire2host.h.


Function Documentation

ldns_status ldns_wire2pkt ( ldns_pkt **  packet,
const uint8_t *  data,
size_t  len 
)

converts the data on the uint8_t bytearray (in wire format) to a DNS packet.

This function will initialize and allocate memory space for the packet structure.

Parameters:
[in] packet pointer to the structure to hold the packet
[in] data pointer to the buffer with the data
[in] len the length of the data buffer (in bytes)
Returns:
LDNS_STATUS_OK if everything succeeds, error otherwise

Definition at line 370 of file wire2host.c.

References ldns_pkt_additional(), ldns_pkt_ancount(), ldns_pkt_answer(), ldns_pkt_arcount(), ldns_pkt_authority(), ldns_pkt_free(), ldns_pkt_new(), ldns_pkt_nscount(), ldns_pkt_qdcount(), ldns_pkt_question(), ldns_pkt_set_arcount(), ldns_pkt_set_edns_data(), ldns_pkt_set_edns_extended_rcode(), ldns_pkt_set_edns_udp_size(), ldns_pkt_set_edns_version(), ldns_pkt_set_edns_z(), ldns_pkt_set_size(), ldns_pkt_set_tsig(), ldns_rdf_clone(), ldns_rr_free(), ldns_rr_get_class(), ldns_rr_get_type(), ldns_rr_list_push_rr(), ldns_rr_rdf(), ldns_rr_ttl(), LDNS_RR_TYPE_OPT, LDNS_RR_TYPE_TSIG, LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_AUTHORITY, LDNS_SECTION_QUESTION, LDNS_STATUS_CHECK_GOTO, LDNS_STATUS_INTERNAL_ERR, LDNS_STATUS_OK, LDNS_STATUS_PACKET_OVERFLOW, LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL, LDNS_STATUS_WIRE_INCOMPLETE_ANSWER, LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY, LDNS_STATUS_WIRE_INCOMPLETE_QUESTION, and ldns_wire2rr().

ldns_status ldns_buffer2pkt_wire ( ldns_pkt **  packet,
ldns_buffer buffer 
)

converts the data on the uint8_t bytearray (in wire format) to a DNS packet.

This function will initialize and allocate memory space for the packet structure.

Parameters:
[in] packet pointer to the structure to hold the packet
[in] buffer the buffer with the data
Returns:
LDNS_STATUS_OK if everything succeeds, error otherwise

Definition at line 361 of file wire2host.c.

References ldns_wire2pkt().

ldns_status ldns_wire2dname ( ldns_rdf **  dname,
const uint8_t *  wire,
size_t  max,
size_t *  pos 
)

converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.

This function will initialize and allocate memory space for the dname structure. The length of the wiredata of this rdf is added to the *pos value.

Parameters:
[in] dname pointer to the structure to hold the rdata value
[in] wire pointer to the buffer with the data
[in] max the length of the data buffer (in bytes)
[in] pos the position of the rdf in the buffer (ie. the number of bytes from the start of the buffer)
Returns:
LDNS_STATUS_OK if everything succeeds, error otherwise

Definition at line 56 of file wire2host.c.

References LDNS_MAX_DOMAINLEN, LDNS_MAX_LABELLEN, LDNS_MAX_POINTERS, ldns_rdf_new_frm_data(), LDNS_RDF_TYPE_DNAME, LDNS_STATUS_DOMAINNAME_OVERFLOW, LDNS_STATUS_INVALID_POINTER, LDNS_STATUS_LABEL_OVERFLOW, LDNS_STATUS_MEM_ERR, LDNS_STATUS_OK, and LDNS_STATUS_PACKET_OVERFLOW.

ldns_status ldns_wire2rdf ( ldns_rr rr,
const uint8_t *  wire,
size_t  max,
size_t *  pos 
)

converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the list of rdfs of the given rr.

This function will initialize and allocate memory space for the dname structures. The length of the wiredata of these rdfs is added to the *pos value.

All rdfs belonging to the RR are read; the rr should have no rdfs yet. An error is returned if the format cannot be parsed.

Parameters:
[in] rr pointer to the ldns_rr structure to hold the rdata value
[in] wire pointer to the buffer with the data
[in] max the length of the data buffer (in bytes)
[in] pos the position of the rdf in the buffer (ie. the number of bytes from the start of the buffer)
Returns:
LDNS_STATUS_OK if everything succeeds, error otherwise

Definition at line 156 of file wire2host.c.

References ldns_rdf_new(), LDNS_RDF_SIZE_16BYTES, LDNS_RDF_SIZE_6BYTES, LDNS_RDF_SIZE_BYTE, LDNS_RDF_SIZE_DOUBLEWORD, LDNS_RDF_SIZE_WORD, LDNS_RDF_TYPE_A, LDNS_RDF_TYPE_AAAA, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_APL, LDNS_RDF_TYPE_ATMA, LDNS_RDF_TYPE_B32_EXT, LDNS_RDF_TYPE_B64, LDNS_RDF_TYPE_CERT_ALG, LDNS_RDF_TYPE_CLASS, LDNS_RDF_TYPE_DNAME, LDNS_RDF_TYPE_HEX, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_INT16_DATA, LDNS_RDF_TYPE_INT32, LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_IPSECKEY, LDNS_RDF_TYPE_LOC, LDNS_RDF_TYPE_NONE, LDNS_RDF_TYPE_NSAP, LDNS_RDF_TYPE_NSEC, LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, LDNS_RDF_TYPE_NSEC3_SALT, LDNS_RDF_TYPE_PERIOD, LDNS_RDF_TYPE_SERVICE, LDNS_RDF_TYPE_STR, LDNS_RDF_TYPE_TIME, LDNS_RDF_TYPE_TSIG, LDNS_RDF_TYPE_TSIGTIME, LDNS_RDF_TYPE_TYPE, LDNS_RDF_TYPE_UNKNOWN, LDNS_RDF_TYPE_WKS, ldns_rr_descript(), ldns_rr_descriptor_field_type(), ldns_rr_descriptor_maximum(), ldns_rr_get_type(), ldns_rr_push_rdf(), LDNS_STATUS_CHECK_RETURN, LDNS_STATUS_MEM_ERR, LDNS_STATUS_OK, LDNS_STATUS_PACKET_OVERFLOW, ldns_wire2dname(), and LDNS_XMALLOC.

ldns_status ldns_wire2rr ( ldns_rr **  rr,
const uint8_t *  wire,
size_t  max,
size_t *  pos,
ldns_pkt_section  section 
)

converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.

This function will initialize and allocate memory space for the rr structure. The length of the wiredata of this rr is added to the *pos value.

Parameters:
[in] rr pointer to the structure to hold the rdata value
[in] wire pointer to the buffer with the data
[in] max the length of the data buffer (in bytes)
[in] pos the position of the rr in the buffer (ie. the number of bytes from the start of the buffer)
[in] section the section in the packet the rr is meant for
Returns:
LDNS_STATUS_OK if everything succeeds, error otherwise

Definition at line 285 of file wire2host.c.

References ldns_rr_free(), ldns_rr_new(), ldns_rr_set_class(), ldns_rr_set_owner(), ldns_rr_set_question(), ldns_rr_set_ttl(), ldns_rr_set_type(), LDNS_SECTION_QUESTION, LDNS_STATUS_CHECK_GOTO, LDNS_STATUS_OK, LDNS_STATUS_PACKET_OVERFLOW, ldns_wire2dname(), and ldns_wire2rdf().


Generated on Thu Apr 5 23:05:31 2012 for ldns by  doxygen 1.4.7