21 #include <openssl/rand.h>
28 #define LDNS_EDNS_MASK_DO_BIT 0x8000
29 #define LDNS_EDNS_MASK_UNASSIGNED (0xFFFF & ~LDNS_EDNS_MASK_DO_BIT)
185 return packet->
_size;
203 return packet->timestamp;
601 packet->
timestamp.tv_sec = timeval.tv_sec;
602 packet->
timestamp.tv_usec = timeval.tv_usec;
791 size_t size = ldns_read_uint16(&wire[pos+2]);
794 if (pos + size > max) {
804 memcpy(data, &wire[pos], size);
1023 ldns_pkt_query_new_frm_str_internal(
ldns_pkt **p,
const char *name,
1050 if (rr_class == 0) {
1086 return ldns_pkt_query_new_frm_str_internal(p, name, rr_type,
1087 rr_class, flags, NULL);
1098 authsoa_rr = ldns_pkt_authsoa(name_rdf, rr_class);
1103 rr_class, flags, authsoa_rr);
1131 if (rr_class == 0) {
1153 return ldns_pkt_query_new_internal(rr_name, rr_type,
1154 rr_class, flags, NULL);
1163 authsoa_rr = ldns_pkt_authsoa(rr_name, rr_class);
1166 rr_class, flags, authsoa_rr);
int ldns_dname_compare(const ldns_rdf *dname1, const ldns_rdf *dname2)
Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6.
ldns_edns_option_list * ldns_edns_option_list_new(void)
allocates space for a new list of EDNS options
enum ldns_enum_edns_option ldns_edns_option_code
signed char ldns_edns_option_list_push(ldns_edns_option_list *options_list, ldns_edns_option *option)
adds an EDNS option at the end of the list of options.
void ldns_edns_option_list_deep_free(ldns_edns_option_list *options_list)
ldns_edns_option_list * ldns_edns_option_list_clone(ldns_edns_option_list *options_list)
clone the EDNS options list and it's contents
ldns_edns_option * ldns_edns_new(ldns_edns_option_code code, size_t size, void *data)
allocates a new EDNS structure and fills it.
enum ldns_enum_status ldns_status
Including this file will include all ldns files, and define some lookup tables.
ldns_pkt * ldns_pkt_clone(const ldns_pkt *pkt)
clones the given packet, creating a fully allocated copy
void ldns_pkt_free(ldns_pkt *packet)
frees the packet structure and all data that it contains.
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet's edns version
void ldns_pkt_set_ancount(ldns_pkt *packet, uint16_t ancount)
Set the packet's an count.
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *packet)
Return the packet's answerfrom.
void ldns_pkt_set_rd(ldns_pkt *packet, signed char rd)
Set the packet's rd bit.
void ldns_pkt_set_querytime(ldns_pkt *packet, uint32_t time)
Set the packet's query time.
void ldns_pkt_set_tsig(ldns_pkt *pkt, ldns_rr *rr)
Set the packet's tsig rr.
signed char ldns_pkt_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
push a rr_list on a packet
void ldns_pkt_set_tc(ldns_pkt *packet, signed char tc)
Set the packet's tc bit.
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *packet)
Read the packet's code.
signed char ldns_pkt_edns(const ldns_pkt *pkt)
returns true if this packet needs and EDNS rr to be sent.
ldns_pkt * ldns_pkt_ixfr_request_new(ldns_rdf *rr_name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, type and class.
signed char ldns_pkt_safe_push_rr(ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr)
push an rr on a packet, provided the RR is not there.
signed char ldns_pkt_rr(const ldns_pkt *pkt, ldns_pkt_section sec, const ldns_rr *rr)
check to see if an rr exist in the packet
void ldns_pkt_set_edns_udp_size(ldns_pkt *packet, uint16_t s)
Set the packet's edns udp size.
void ldns_pkt_set_opcode(ldns_pkt *packet, ldns_pkt_opcode opcode)
Set the packet's opcode.
void ldns_pkt_set_additional(ldns_pkt *p, ldns_rr_list *rr)
directly set the additional section
void ldns_pkt_set_aa(ldns_pkt *packet, signed char aa)
Set the packet's aa bit.
void ldns_pkt_set_random_id(ldns_pkt *packet)
Set the packet's id to a random value.
void ldns_pkt_set_edns_option_list(ldns_pkt *packet, ldns_edns_option_list *list)
Set the packet's structured EDNS data.
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
ldns_edns_option_list * pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
#define LDNS_EDNS_MASK_UNASSIGNED
struct timeval ldns_pkt_timestamp(const ldns_pkt *packet)
Return the packet's timestamp.
void ldns_pkt_set_nscount(ldns_pkt *packet, uint16_t nscount)
Set the packet's ns count.
void ldns_pkt_set_authority(ldns_pkt *p, ldns_rr_list *rr)
directly set the authority section
void ldns_pkt_set_ra(ldns_pkt *packet, signed char ra)
Set the packet's ra bit.
void ldns_pkt_set_timestamp(ldns_pkt *packet, struct timeval timeval)
Set the packet's timestamp.
void ldns_pkt_set_cd(ldns_pkt *packet, signed char cd)
Set the packet's cd bit.
ldns_rr_list * ldns_pkt_rr_list_by_name(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_pkt_section sec)
return all the rr with a specific name from a packet.
void ldns_pkt_set_size(ldns_pkt *packet, size_t s)
Set the packet's size.
signed char ldns_pkt_aa(const ldns_pkt *packet)
Read the packet's aa bit.
ldns_pkt * ldns_pkt_new(void)
allocates and initializes a ldns_pkt structure.
signed char ldns_pkt_empty(ldns_pkt *p)
check if a packet is empty
#define LDNS_EDNS_MASK_DO_BIT
signed char ldns_pkt_set_flags(ldns_pkt *packet, uint16_t flags)
sets the flags in a packet.
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
uint16_t ldns_pkt_edns_unassigned(const ldns_pkt *packet)
return the packet's EDNS header bits that are unassigned.
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
signed char ldns_pkt_push_rr(ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr)
push an rr on a packet
ldns_rr_list * ldns_pkt_rr_list_by_name_and_type(const ldns_pkt *packet, const ldns_rdf *ownername, ldns_rr_type type, ldns_pkt_section sec)
return all the rr with a specific type and type from a packet.
void ldns_pkt_set_answer(ldns_pkt *p, ldns_rr_list *rr)
directly set the answer section
void ldns_pkt_set_question(ldns_pkt *p, ldns_rr_list *rr)
directly set the question section
void ldns_pkt_set_edns_do(ldns_pkt *packet, signed char value)
Set the packet's edns do bit.
void ldns_pkt_set_qdcount(ldns_pkt *packet, uint16_t qdcount)
Set the packet's qd count.
ldns_rr_list * ldns_pkt_all_noquestion(const ldns_pkt *packet)
Return the packet's answer, authority and additional sections concatenated, in a new rr_list clone.
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
signed char ldns_pkt_cd(const ldns_pkt *packet)
Read the packet's cd bit.
size_t ldns_pkt_size(const ldns_pkt *packet)
Return the packet's size in bytes.
void ldns_pkt_set_edns_z(ldns_pkt *packet, uint16_t z)
Set the packet's edns z value.
signed char ldns_pkt_qr(const ldns_pkt *packet)
Read the packet's qr bit.
uint32_t ldns_pkt_querytime(const ldns_pkt *packet)
Return the packet's querytime.
void ldns_pkt_set_ad(ldns_pkt *packet, signed char ad)
Set the packet's ad bit.
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet's edns extended rcode
uint16_t ldns_pkt_section_count(const ldns_pkt *packet, ldns_pkt_section s)
Return the number of RRs in the given section.
void ldns_pkt_set_qr(ldns_pkt *packet, signed char qr)
Set the packet's qr bit.
void ldns_pkt_set_edns_data(ldns_pkt *packet, ldns_rdf *data)
Set the packet's EDNS data.
ldns_pkt_type ldns_pkt_reply_type(const ldns_pkt *p)
looks inside the packet to determine what kind of packet it is, AUTH, NXDOMAIN, REFERRAL,...
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
signed char ldns_pkt_tc(const ldns_pkt *packet)
Read the packet's tc bit.
signed char ldns_pkt_rd(const ldns_pkt *packet)
Read the packet's rd bit.
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
signed char ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet's edns do bit
signed char ldns_pkt_safe_push_rr_list(ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
push an rr_list to a packet, provided the RRs are not already there.
ldns_rr_list * ldns_pkt_all(const ldns_pkt *packet)
Return the packet's question, answer, authority and additional sections concatenated,...
signed char ldns_pkt_ra(const ldns_pkt *packet)
Read the packet's ra bit.
ldns_rr_list * ldns_pkt_get_section_clone(const ldns_pkt *packet, ldns_pkt_section s)
return all the rr_list's in the packet.
void ldns_pkt_set_id(ldns_pkt *packet, uint16_t id)
Set the packet's id.
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
signed char ldns_pkt_ad(const ldns_pkt *packet)
Read the packet's ad bit.
ldns_lookup_table ldns_edns_flags[]
EDNS flags.
void ldns_pkt_set_edns_extended_rcode(ldns_pkt *packet, uint8_t c)
Set the packet's edns extended rcode.
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's EDNS data
ldns_status ldns_pkt_ixfr_request_new_frm_str(ldns_pkt **p, const char *name, ldns_rr_class rr_class, uint16_t flags, ldns_rr *soa)
creates an IXFR request packet for the given name, class.
ldns_rr * ldns_pkt_tsig(const ldns_pkt *pkt)
Return the packet's tsig pseudo rr's.
void ldns_pkt_set_answerfrom(ldns_pkt *packet, ldns_rdf *answerfrom)
Set the packet's answering server.
void ldns_pkt_set_section_count(ldns_pkt *packet, ldns_pkt_section s, uint16_t count)
Set a packet's section count to x.
ldns_status ldns_pkt_query_new_frm_str(ldns_pkt **p, const char *name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a query packet for the given name, type, class.
uint16_t ldns_pkt_edns_z(const ldns_pkt *packet)
return the packet's edns z value
ldns_edns_option_list * ldns_pkt_edns_get_option_list(ldns_pkt *packet)
Returns a list of structured EDNS options.
void ldns_pkt_set_arcount(ldns_pkt *packet, uint16_t arcount)
Set the packet's arcount.
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's response code.
void ldns_pkt_set_rcode(ldns_pkt *packet, uint8_t rcode)
Set the packet's response code.
ldns_pkt * ldns_pkt_query_new(ldns_rdf *rr_name, ldns_rr_type rr_type, ldns_rr_class rr_class, uint16_t flags)
creates a packet with a query in it for the given name, type and class.
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
void ldns_pkt_set_edns_version(ldns_pkt *packet, uint8_t v)
Set the packet's edns version.
void ldns_pkt_set_edns_unassigned(ldns_pkt *packet, uint16_t value)
Set the packet's EDNS header bits that are unassigned.
ldns_rr_list * ldns_pkt_rr_list_by_type(const ldns_pkt *packet, ldns_rr_type type, ldns_pkt_section sec)
return all the rr with a specific type from a packet.
enum ldns_enum_pkt_type ldns_pkt_type
enum ldns_enum_pkt_rcode ldns_pkt_rcode
enum ldns_enum_pkt_opcode ldns_pkt_opcode
enum ldns_enum_pkt_section ldns_pkt_section
@ LDNS_SECTION_ANY
bogus section, if not interested
@ LDNS_SECTION_ADDITIONAL
@ LDNS_SECTION_ANY_NOQUESTION
used to get all non-question rrs from a packet
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
@ LDNS_RDF_TYPE_INT32
32 bits
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
ldns_rdf * ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value)
returns an rdf that contains the given int32 value.
void ldns_rdf_free(ldns_rdf *rd)
frees a rdf structure, leaving the data pointer intact.
ldns_rdf * ldns_rdf_clone(const ldns_rdf *rd)
clones a rdf structure.
void ldns_rr_list_free(ldns_rr_list *rr_list)
frees an rr_list structure.
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
void ldns_rr_list_deep_free(ldns_rr_list *rr_list)
frees an rr_list structure and all rrs contained therein.
void ldns_rr_free(ldns_rr *rr)
frees an RR structure
void ldns_rr_set_owner(ldns_rr *rr, ldns_rdf *owner)
sets the owner in the rr structure.
signed char ldns_rr_list_contains_rr(const ldns_rr_list *rr_list, const ldns_rr *rr)
returns true if the given rr is one of the rrs in the list, or if it is equal to one
enum ldns_enum_rr_type ldns_rr_type
void ldns_rr_set_type(ldns_rr *rr, ldns_rr_type rr_type)
sets the type in the rr.
@ LDNS_RR_TYPE_A
a host address
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
@ LDNS_RR_TYPE_NS
an authoritative name server
signed char ldns_rr_list_push_rr(ldns_rr_list *rr_list, const ldns_rr *rr)
pushes an rr to an rrlist.
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
void ldns_rr_set_question(ldns_rr *rr, signed char question)
sets the question flag in the rr structure.
ldns_rr_list * ldns_rr_list_cat_clone(const ldns_rr_list *left, const ldns_rr_list *right)
concatenates two ldns_rr_lists together, but makes clones of the rr's (instead of pointer copying).
enum ldns_enum_rr_class ldns_rr_class
void ldns_rr_set_class(ldns_rr *rr, ldns_rr_class rr_class)
sets the class in the rr.
ldns_rr_list * ldns_rr_list_new(void)
creates a new rr_list structure.
signed char ldns_rr_push_rdf(ldns_rr *rr, const ldns_rdf *f)
sets rd_field member, it will be placed in the next available spot.
@ LDNS_RR_CLASS_IN
the Internet
ldns_rr * ldns_rr_clone(const ldns_rr *rr)
clones a rr and all its data
ldns_rr_list * ldns_rr_list_clone(const ldns_rr_list *rrlist)
clones an rrlist.
ldns_rr * ldns_rr_new(void)
creates a new rr structure.
ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str)
convert a dname string into wireformat
The struct that stores an ordered EDNS option.
signed char _rd
Recursion desired.
uint16_t _id
Id of a packet.
ldns_pkt_opcode _opcode
Query type.
signed char _cd
Checking disabled.
signed char _ra
Recursion available.
uint16_t _ancount
answer sec
signed char _qr
Query bit (0=query, 1=answer)
signed char _tc
Packet truncated.
signed char _ad
Authentic data.
uint16_t _qdcount
question sec
uint8_t _rcode
Response code.
uint16_t _nscount
auth sec
signed char _aa
Authoritative answer.
A general purpose lookup table.
struct timeval timestamp
Timestamp of the time the packet was sent or created.
uint8_t _edns_extended_rcode
EDNS0 Extended rcode.
ldns_rr_list * _authority
Authority section.
ldns_hdr * _header
Header section.
uint32_t _querytime
The duration of the query this packet is an answer to.
uint16_t _edns_udp_size
EDNS0 available buffer size, see RFC2671.
ldns_rdf * _answerfrom
an rdf (A or AAAA) with the IP address of the server it is from
uint8_t _edns_version
EDNS Version.
size_t _size
The size of the wire format of the packet in octets.
ldns_rr_list * _answer
Answer section.
ldns_rdf * _edns_data
Arbitrary EDNS rdata.
ldns_edns_option_list * _edns_list
Structed EDNS data.
uint16_t _edns_z
Reserved EDNS data bits.
ldns_rr_list * _additional
Additional section.
ldns_rr * _tsig_rr
Optional tsig rr.
ldns_rr_list * _question
Question section.
Resource record data field.
List or Set of Resource Records.
#define LDNS_MALLOC(type)
Memory management macros.
#define LDNS_XMALLOC(type, count)
uint16_t ldns_get_random(void)
Get random number.