ldns documentation

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

Macros | Functions | Variables
packet.c File Reference

Go to the source code of this file.

## Macros
#define | LDNS_EDNS_MASK_DO_BIT 0x8000

## Functions
uint16_t | ldns_pkt_id (const ldns_pkt *packet)
| Read the packet id. More...
bool | ldns_pkt_qr (const ldns_pkt *packet)
| Read the packet's qr bit. More...
bool | ldns_pkt_aa (const ldns_pkt *packet)
| Read the packet's aa bit. More...
bool | ldns_pkt_tc (const ldns_pkt *packet)
| Read the packet's tc bit. More...
bool | ldns_pkt_rd (const ldns_pkt *packet)
| Read the packet's rd bit. More...
bool | ldns_pkt_cd (const ldns_pkt *packet)
| Read the packet's cd bit. More...
bool | ldns_pkt_ra (const ldns_pkt *packet)
| Read the packet's ra bit. More...
bool | ldns_pkt_ad (const ldns_pkt *packet)
| Read the packet's ad bit. More...
ldns_pkt_opcode | ldns_pkt_get_opcode (const ldns_pkt *packet)
| Read the packet's code. More...
ldns_pkt_rcode | ldns_pkt_get_rcode (const ldns_pkt *packet)
| Return the packet's respons code. More...
uint16_t | ldns_pkt_qdcount (const ldns_pkt *packet)
| Return the packet's qd count. More...
uint16_t | ldns_pkt_ancount (const ldns_pkt *packet)
| Return the packet's an count. More...
uint16_t | ldns_pkt_nscount (const ldns_pkt *packet)
| Return the packet's ns count. More...
uint16_t | ldns_pkt_arcount (const ldns_pkt *packet)
| Return the packet's ar count. More...
ldns_rr_list * | ldns_pkt_question (const ldns_pkt *packet)
| Return the packet's question section. More...
ldns_rr_list * | ldns_pkt_answer (const ldns_pkt *packet)
| Return the packet's answer section. More...
ldns_rr_list * | ldns_pkt_authority (const ldns_pkt *packet)
| Return the packet's authority section. More...
ldns_rr_list * | ldns_pkt_additional (const ldns_pkt *packet)
| Return the packet's additional section. More...
ldns_rr_list * | ldns_pkt_all (const ldns_pkt *packet)
| Return the packet's question, answer, authority and additional sections concatenated, in a new rr_list clone. More...
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. More...
size_t | ldns_pkt_size (const ldns_pkt *packet)
| Return the packet's size in bytes. More...
uint32_t | ldns_pkt_querytime (const ldns_pkt *packet)
| Return the packet's querytime. More...
ldns_rdf * | ldns_pkt_answerfrom (const ldns_pkt *packet)
| Return the packet's answerfrom. More...
struct timeval | ldns_pkt_timestamp (const ldns_pkt *packet)
| Return the packet's timestamp. More...
uint16_t | ldns_pkt_edns_udp_size (const ldns_pkt *packet)
| return the packet's edns udp size More...
uint8_t | ldns_pkt_edns_extended_rcode (const ldns_pkt *packet)
| return the packet's edns extended rcode More...
uint8_t | ldns_pkt_edns_version (const ldns_pkt *packet)
| return the packet's edns version More...
uint16_t | ldns_pkt_edns_z (const ldns_pkt *packet)
| return the packet's edns z value More...
bool | ldns_pkt_edns_do (const ldns_pkt *packet)
| return the packet's edns do bit More...
void | ldns_pkt_set_edns_do (ldns_pkt *packet, bool value)
ldns_rdf * | ldns_pkt_edns_data (const ldns_pkt *packet)
| return the packet's edns data More...
ldns_rr_list * | ldns_pkt_rr_list_by_name (ldns_pkt *packet, ldns_rdf *ownername, ldns_pkt_section sec)
| return all the rr with a specific name from a packet. More...
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. More...
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. More...
bool | ldns_pkt_rr (ldns_pkt *pkt, ldns_pkt_section sec, ldns_rr *rr)
| check to see if an rr exist in the packet More...
uint16_t | ldns_pkt_section_count (const ldns_pkt *packet, ldns_pkt_section s)
| Return the number of RRs in the given section. More...
bool | ldns_pkt_empty (ldns_pkt *p)
| check if a packet is empty More...
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. More...
ldns_rr * | ldns_pkt_tsig (const ldns_pkt *pkt)
| Return the packet's tsig pseudo rr's. More...
void | ldns_pkt_set_id (ldns_pkt *packet, uint16_t id)
| Set the packet's id. More...
void | ldns_pkt_set_random_id (ldns_pkt *packet)
| Set the packet's id to a random value. More...
void | ldns_pkt_set_qr (ldns_pkt *packet, bool qr)
void | ldns_pkt_set_aa (ldns_pkt *packet, bool aa)
void | ldns_pkt_set_tc (ldns_pkt *packet, bool tc)
void | ldns_pkt_set_rd (ldns_pkt *packet, bool rd)
void | ldns_pkt_set_additional (ldns_pkt *p, ldns_rr_list *rr)
| directly set the additional section More...
void | ldns_pkt_set_question (ldns_pkt *p, ldns_rr_list *rr)
| directly set the question section More...
void | ldns_pkt_set_answer (ldns_pkt *p, ldns_rr_list *rr)
| directly set the answer section More...
void | ldns_pkt_set_authority (ldns_pkt *p, ldns_rr_list *rr)
| directly set the auhority section More...
void | ldns_pkt_set_cd (ldns_pkt *packet, bool cd)
void | ldns_pkt_set_ra (ldns_pkt *packet, bool ra)
void | ldns_pkt_set_ad (ldns_pkt *packet, bool ad)
void | ldns_pkt_set_opcode (ldns_pkt *packet, ldns_pkt_opcode opcode)
| Set the packet's opcode. More...
void | ldns_pkt_set_rcode (ldns_pkt *packet, uint8_t rcode)
| Set the packet's respons code. More...
void | ldns_pkt_set_qdcount (ldns_pkt *packet, uint16_t qdcount)
| Set the packet's qd count. More...
void | ldns_pkt_set_ancount (ldns_pkt *packet, uint16_t ancount)
| Set the packet's an count. More...
void | ldns_pkt_set_nscount (ldns_pkt *packet, uint16_t nscount)
| Set the packet's ns count. More...
void | ldns_pkt_set_arcount (ldns_pkt *packet, uint16_t arcount)
| Set the packet's arcount. More...
void | ldns_pkt_set_querytime (ldns_pkt *packet, uint32_t time)
| Set the packet's query time. More...
void | ldns_pkt_set_answerfrom (ldns_pkt *packet, ldns_rdf *answerfrom)
| Set the packet's answering server. More...
void | ldns_pkt_set_timestamp (ldns_pkt *packet, struct timeval timeval)
| Set the packet's timestamp. More...
void | ldns_pkt_set_size (ldns_pkt *packet, size_t s)
| Set the packet's size. More...
void | ldns_pkt_set_edns_udp_size (ldns_pkt *packet, uint16_t s)
| Set the packet's edns udp size. More...
void | ldns_pkt_set_edns_extended_rcode (ldns_pkt *packet, uint8_t c)
| Set the packet's edns extended rcode. More...
void | ldns_pkt_set_edns_version (ldns_pkt *packet, uint8_t v)
| Set the packet's edns version. More...
void | ldns_pkt_set_edns_z (ldns_pkt *packet, uint16_t z)
| Set the packet's edns z value. More...
void | ldns_pkt_set_edns_data (ldns_pkt *packet, ldns_rdf *data)
| Set the packet's edns data. More...
void | ldns_pkt_set_section_count (ldns_pkt *packet, ldns_pkt_section s, uint16_t count)
| Set a packet's section count to x. More...
void | ldns_pkt_set_tsig (ldns_pkt *pkt, ldns_rr *rr)
| Set the packet's tsig rr. More...
bool | ldns_pkt_push_rr (ldns_pkt *packet, ldns_pkt_section section, ldns_rr *rr)
| push an rr on a packet More...
bool | 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. More...
bool | ldns_pkt_push_rr_list (ldns_pkt *p, ldns_pkt_section s, ldns_rr_list *list)
| push a rr_list on a packet More...
bool | 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. More...
bool | ldns_pkt_edns (const ldns_pkt *pkt)
| returns true if this packet needs and EDNS rr to be sent. More...
ldns_pkt * | ldns_pkt_new (void)
| allocates and initializes a ldns_pkt structure. More...
void | ldns_pkt_free (ldns_pkt *packet)
| frees the packet structure and all data that it contains. More...
bool | ldns_pkt_set_flags (ldns_pkt *packet, uint16_t flags)
| sets the flags in a packet. More...
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. More...
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. More...
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. More...
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. More...
ldns_pkt_type | ldns_pkt_reply_type (ldns_pkt *p)
| looks inside the packet to determine what kind of packet it is, AUTH, NXDOMAIN, REFERRAL, etc. More...
ldns_pkt * | ldns_pkt_clone (ldns_pkt *pkt)
| clones the given packet, creating a fully allocated copy More...

## Variables
ldns_lookup_table | ldns_edns_flags []
| EDNS flags. More...

## Macro Definition Documentation

#define LDNS_EDNS_MASK_DO_BIT 0x8000

Definition at line 28 of file packet.c.

## Function Documentation

uint16_t ldns_pkt_id | ( | const ldns_pkt * | p | ) |

Read the packet id.

Parameters

  [in] | p | the packet

Returns
  the packet id

Definition at line 39 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_id.

bool ldns_pkt_qr | ( | const ldns_pkt * | p | ) |

Read the packet's qr bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 45 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_qr.

bool ldns_pkt_aa | ( | const ldns_pkt * | p | ) |

Read the packet's aa bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 51 of file packet.c.

References ldns_struct_hdr::_aa, and ldns_struct_pkt::_header.

bool ldns_pkt_tc | ( | const ldns_pkt * | p | ) |

Read the packet's tc bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 57 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_tc.

bool ldns_pkt_rd | ( | const ldns_pkt * | p | ) |

Read the packet's rd bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 63 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_rd.

bool ldns_pkt_cd | ( | const ldns_pkt * | p | ) |

Read the packet's cd bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 69 of file packet.c.

References ldns_struct_hdr::_cd, and ldns_struct_pkt::_header.

bool ldns_pkt_ra | ( | const ldns_pkt * | p | ) |

Read the packet's ra bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 75 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_ra.

bool ldns_pkt_ad | ( | const ldns_pkt * | p | ) |

Read the packet's ad bit.

Parameters

  [in] | p | the packet

Returns
  value of the bit

Definition at line 81 of file packet.c.

References ldns_struct_hdr::_ad, and ldns_struct_pkt::_header.

ldns_pkt_opcode ldns_pkt_get_opcode | ( | const ldns_pkt * | p | ) |

Read the packet's code.

Parameters

  [in] | p | the packet

Returns
  the opcode

Definition at line 87 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_opcode.

ldns_pkt_rcode ldns_pkt_get_rcode | ( | const ldns_pkt * | p | ) |

Return the packet's respons code.

Parameters

  [in] | p | the packet

Returns
  the respons code

Definition at line 93 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_rcode.

uint16_t ldns_pkt_qdcount | ( | const ldns_pkt * | p | ) |

Return the packet's qd count.

Parameters

  [in] | p | the packet

Returns
  the qd count

Definition at line 99 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_qdcount.

uint16_t ldns_pkt_ancount | ( | const ldns_pkt * | p | ) |

Return the packet's an count.

Parameters

  [in] | p | the packet

Returns
  the an count

Definition at line 105 of file packet.c.

References ldns_struct_hdr::_ancount, and ldns_struct_pkt::_header.

uint16_t ldns_pkt_nscount | ( | const ldns_pkt * | p | ) |

Return the packet's ns count.

Parameters

  [in] | p | the packet

Returns
  the ns count

Definition at line 111 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_nscount.

uint16_t ldns_pkt_arcount | ( | const ldns_pkt * | p | ) |

Return the packet's ar count.

Parameters

  [in] | p | the packet

Returns
  the ar count

Definition at line 117 of file packet.c.

References ldns_struct_hdr::_arcount, and ldns_struct_pkt::_header.

ldns_rr_list* ldns_pkt_question | ( | const ldns_pkt * | p | ) |

Return the packet's question section.

Parameters

  [in] | p | the packet

Returns
  the section

Definition at line 123 of file packet.c.

References ldns_struct_pkt::_question.

ldns_rr_list* ldns_pkt_answer | ( | const ldns_pkt * | p | ) |

Return the packet's answer section.

Parameters

  [in] | p | the packet

Returns
  the section

Definition at line 129 of file packet.c.

References ldns_struct_pkt::_answer.

ldns_rr_list* ldns_pkt_authority | ( | const ldns_pkt * | p | ) |

Return the packet's authority section.

Parameters

  [in] | p | the packet

Returns
  the section

Definition at line 135 of file packet.c.

References ldns_struct_pkt::_authority.

ldns_rr_list* ldns_pkt_additional | ( | const ldns_pkt * | p | ) |

Return the packet's additional section.

Parameters

  [in] | p | the packet

Returns
  the section

Definition at line 141 of file packet.c.

References ldns_struct_pkt::_additional.

ldns_rr_list* ldns_pkt_all | ( | const ldns_pkt * | p | ) |

Return the packet's question, answer, authority and additional sections concatenated, in a new rr_list clone.

Parameters

  [in] | p | the packet

Returns
  the rrs

Definition at line 148 of file packet.c.

References ldns_pkt_additional(), ldns_pkt_answer(), ldns_pkt_authority(), ldns_pkt_question(), ldns_rr_list_cat_clone(), and ldns_rr_list_deep_free().

ldns_rr_list* ldns_pkt_all_noquestion | ( | const ldns_pkt * | p | ) |

Return the packet's answer, authority and additional sections concatenated, in a new rr_list clone.

Like ldns_pkt_all but without the questions.

Parameters

  [in] | p | the packet

Returns
  the rrs except the question rrs

Definition at line 167 of file packet.c.

References ldns_pkt_additional(), ldns_pkt_answer(), ldns_pkt_authority(), ldns_rr_list_cat_clone(), and ldns_rr_list_deep_free().

size_t ldns_pkt_size | ( | const ldns_pkt * | p | ) |

Return the packet's size in bytes.

Parameters

  [in] | p | the packet

Returns
  the size

Definition at line 182 of file packet.c.

References ldns_struct_pkt::_size.

uint32_t ldns_pkt_querytime | ( | const ldns_pkt * | p | ) |

Return the packet's querytime.

Parameters

  [in] | p | the packet

Returns
  the querytime

Definition at line 188 of file packet.c.

References ldns_struct_pkt::_querytime.

ldns_rdf* ldns_pkt_answerfrom | ( | const ldns_pkt * | p | ) |

Return the packet's answerfrom.

Parameters

  [in] | p | packet

Returns
  the name of the server

Definition at line 194 of file packet.c.

References ldns_struct_pkt::_answerfrom.

struct timeval ldns_pkt_timestamp | ( | const ldns_pkt * | p | ) |

Return the packet's timestamp.

Parameters

  [in] | p | the packet

Returns
  the timestamp

Definition at line 200 of file packet.c.

uint16_t ldns_pkt_edns_udp_size | ( | const ldns_pkt * | packet | ) |

return the packet's edns udp size

Parameters

  [in] | packet | the packet

Returns
  the size

Definition at line 206 of file packet.c.

References ldns_struct_pkt::_edns_udp_size.

uint8_t ldns_pkt_edns_extended_rcode | ( | const ldns_pkt * | packet | ) |

return the packet's edns extended rcode

Parameters

  [in] | packet | the packet

Returns
  the rcode

Definition at line 212 of file packet.c.

References ldns_struct_pkt::_edns_extended_rcode.

uint8_t ldns_pkt_edns_version | ( | const ldns_pkt * | packet | ) |

return the packet's edns version

Parameters

  [in] | packet | the packet

Returns
  the version

Definition at line 218 of file packet.c.

References ldns_struct_pkt::_edns_version.

uint16_t ldns_pkt_edns_z | ( | const ldns_pkt * | packet | ) |

return the packet's edns z value

Parameters

  [in] | packet | the packet

Returns
  the z value

Definition at line 224 of file packet.c.

References ldns_struct_pkt::_edns_z.

bool ldns_pkt_edns_do | ( | const ldns_pkt * | packet | ) |

return the packet's edns do bit

Parameters

  [in] | packet | the packet

Returns
  the bit's value

Definition at line 230 of file packet.c.

References ldns_struct_pkt::_edns_z, and LDNS_EDNS_MASK_DO_BIT.

void ldns_pkt_set_edns_do | ( | ldns_pkt * | packet,
|  | bool | value
| ) |  |

Definition at line 236 of file packet.c.

References ldns_struct_pkt::_edns_z, and LDNS_EDNS_MASK_DO_BIT.

ldns_rdf* ldns_pkt_edns_data | ( | const ldns_pkt * | packet | ) |

return the packet's edns data

Parameters

  [in] | packet | the packet

Returns
  the data

Definition at line 246 of file packet.c.

References ldns_struct_pkt::_edns_data.

ldns_rr_list* ldns_pkt_rr_list_by_name | ( | ldns_pkt * | p,
|  | ldns_rdf * | r,
|  | ldns_pkt_section | s
| ) |  |

return all the rr with a specific name from a packet.

Optionally specify from which section in the packet

Parameters

  [in] | p | the packet
  [in] | r | the name
  [in] | s | the packet's section

Returns
  a list with the rr's or NULL if none were found

Definition at line 253 of file packet.c.

References ldns_dname_compare(), ldns_pkt_get_section_clone(), ldns_rr_list_new(), ldns_rr_list_push_rr(), ldns_rr_list_rr(), ldns_rr_list_rr_count(), and ldns_rr_owner().

ldns_rr_list* ldns_pkt_rr_list_by_type | ( | const ldns_pkt * | p,
|  | ldns_rr_type | t,
|  | ldns_pkt_section | s
| ) |  |

return all the rr with a specific type from a packet.

Optionally specify from which section in the packet

Parameters

  [in] | p | the packet
  [in] | t | the type
  [in] | s | the packet's section

Returns
  a list with the rr's or NULL if none were found

Definition at line 284 of file packet.c.

References ldns_pkt_get_section_clone(), ldns_rr_clone(), ldns_rr_get_type(), ldns_rr_list_deep_free(), ldns_rr_list_free(), ldns_rr_list_new(), ldns_rr_list_push_rr(), ldns_rr_list_rr(), and ldns_rr_list_rr_count().

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.

Optionally specify from which section in the packet

Parameters

  [in] | packet | the packet
  [in] | ownername | the name
  [in] | type | the type
  [in] | sec | the packet's section

Returns
  a list with the rr's or NULL if none were found

Definition at line 320 of file packet.c.

References ldns_dname_compare(), ldns_pkt_get_section_clone(), ldns_rr_clone(), ldns_rr_get_type(), ldns_rr_list_deep_free(), ldns_rr_list_free(), ldns_rr_list_new(), ldns_rr_list_push_rr(), ldns_rr_list_rr(), ldns_rr_list_rr_count(), and ldns_rr_owner().

bool ldns_pkt_rr | ( | ldns_pkt * | pkt,
|  | ldns_pkt_section | sec,
|  | ldns_rr * | rr
| ) |  |

check to see if an rr exist in the packet

Parameters

  [in] | pkt | the packet to examine
  [in] | sec | in which section to look
  [in] | rr | the rr to look for

Definition at line 357 of file packet.c.

References ldns_pkt_additional(), ldns_pkt_answer(), ldns_pkt_authority(), ldns_pkt_question(), ldns_rr_list_contains_rr(), LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_ANY, LDNS_SECTION_ANY_NOQUESTION, LDNS_SECTION_AUTHORITY, and LDNS_SECTION_QUESTION.

uint16_t ldns_pkt_section_count | ( | const ldns_pkt * | p,
|  | ldns_pkt_section | s
| ) |  |

Return the number of RRs in the given section.

Returns the sum of all RRs when LDNS_SECTION_ANY is given. Returns the sum of all non-question RRs when LDNS_SECTION_ANY_NOQUESTION is given.

Parameters

  [in] | p | the packet
  [in] | s | the section

Returns
  the number of RRs in the given section

Definition at line 383 of file packet.c.

References ldns_pkt_ancount(), ldns_pkt_arcount(), ldns_pkt_nscount(), ldns_pkt_qdcount(), LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_ANY, LDNS_SECTION_ANY_NOQUESTION, LDNS_SECTION_AUTHORITY, and LDNS_SECTION_QUESTION.

bool ldns_pkt_empty | ( | ldns_pkt * | p | ) |

check if a packet is empty

Parameters

  [in] | p | packet

Returns
  true: empty, false: not empty

Definition at line 409 of file packet.c.

References ldns_pkt_section_count(), and LDNS_SECTION_ANY.

ldns_rr_list* ldns_pkt_get_section_clone | ( | const ldns_pkt * | p,
|  | ldns_pkt_section | s
| ) |  |

return all the rr_list's in the packet.

Clone the lists, instead of returning pointers.

Parameters

  [in] | p | the packet to look in
  [in] | s | what section(s) to return

Returns
  ldns_rr_list with the rr's or NULL if none were found

Definition at line 423 of file packet.c.

References ldns_pkt_additional(), ldns_pkt_all(), ldns_pkt_all_noquestion(), ldns_pkt_answer(), ldns_pkt_authority(), ldns_pkt_question(), ldns_rr_list_clone(), LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_ANY, LDNS_SECTION_ANY_NOQUESTION, LDNS_SECTION_AUTHORITY, and LDNS_SECTION_QUESTION.

ldns_rr* ldns_pkt_tsig | ( | const ldns_pkt * | p | ) |

Return the packet's tsig pseudo rr's.

Parameters

  [in] | p | the packet

Returns
  the tsig rr

Definition at line 444 of file packet.c.

References ldns_struct_pkt::_tsig_rr.

void ldns_pkt_set_id | ( | ldns_pkt * | p,
|  | uint16_t | id
| ) |  |

Set the packet's id.

Parameters

  [in] | p | the packet
  [in] | id | the id to set

Definition at line 450 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_id.

void ldns_pkt_set_random_id | ( | ldns_pkt * | p | ) |

Set the packet's id to a random value.

Parameters

  [in] | p | the packet

Definition at line 456 of file packet.c.

References ldns_get_random(), and ldns_pkt_set_id().

void ldns_pkt_set_qr | ( | ldns_pkt * | packet,
|  | bool | qr
| ) |  |

Definition at line 464 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_qr.

void ldns_pkt_set_aa | ( | ldns_pkt * | packet,
|  | bool | aa
| ) |  |

Definition at line 470 of file packet.c.

References ldns_struct_hdr::_aa, and ldns_struct_pkt::_header.

void ldns_pkt_set_tc | ( | ldns_pkt * | packet,
|  | bool | tc
| ) |  |

Definition at line 476 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_tc.

void ldns_pkt_set_rd | ( | ldns_pkt * | packet,
|  | bool | rd
| ) |  |

Definition at line 482 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_rd.

void ldns_pkt_set_additional | ( | ldns_pkt * | p,
|  | ldns_rr_list * | rr
| ) |  |

directly set the additional section

Parameters

  [in] | p | packet to operate on
  [in] | rr | rrlist to set

Definition at line 488 of file packet.c.

References ldns_struct_pkt::_additional.

void ldns_pkt_set_question | ( | ldns_pkt * | p,
|  | ldns_rr_list * | rr
| ) |  |

directly set the question section

Parameters

  [in] | p | packet to operate on
  [in] | rr | rrlist to set

Definition at line 494 of file packet.c.

References ldns_struct_pkt::_question.

void ldns_pkt_set_answer | ( | ldns_pkt * | p,
|  | ldns_rr_list * | rr
| ) |  |

directly set the answer section

Parameters

  [in] | p | packet to operate on
  [in] | rr | rrlist to set

Definition at line 500 of file packet.c.

References ldns_struct_pkt::_answer.

void ldns_pkt_set_authority | ( | ldns_pkt * | p,
|  | ldns_rr_list * | rr
| ) |  |

directly set the auhority section

Parameters

  [in] | p | packet to operate on
  [in] | rr | rrlist to set

Definition at line 506 of file packet.c.

References ldns_struct_pkt::_authority.

void ldns_pkt_set_cd | ( | ldns_pkt * | packet,
|  | bool | cd
| ) |  |

Definition at line 512 of file packet.c.

References ldns_struct_hdr::_cd, and ldns_struct_pkt::_header.

void ldns_pkt_set_ra | ( | ldns_pkt * | packet,
|  | bool | ra
| ) |  |

Definition at line 518 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_ra.

void ldns_pkt_set_ad | ( | ldns_pkt * | packet,
|  | bool | ad
| ) |  |

Definition at line 524 of file packet.c.

References ldns_struct_hdr::_ad, and ldns_struct_pkt::_header.

void ldns_pkt_set_opcode | ( | ldns_pkt * | p,
|  | ldns_pkt_opcode | c
| ) |  |

Set the packet's opcode.

Parameters

  [in] | p | the packet
  [in] | c | the opcode

Definition at line 530 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_opcode.

void ldns_pkt_set_rcode | ( | ldns_pkt * | p,
|  | uint8_t | c
| ) |  |

Set the packet's respons code.

Parameters

  [in] | p | the packet
  [in] | c | the rcode

Definition at line 536 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_rcode.

void ldns_pkt_set_qdcount | ( | ldns_pkt * | p,
|  | uint16_t | c
| ) |  |

Set the packet's qd count.

Parameters

  [in] | p | the packet
  [in] | c | the count

Definition at line 542 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_qdcount.

void ldns_pkt_set_ancount | ( | ldns_pkt * | p,
|  | uint16_t | c
| ) |  |

Set the packet's an count.

Parameters

  [in] | p | the packet
  [in] | c | the count

Definition at line 548 of file packet.c.

References ldns_struct_hdr::_ancount, and ldns_struct_pkt::_header.

void ldns_pkt_set_nscount | ( | ldns_pkt * | p,
|  | uint16_t | c
| ) |  |

Set the packet's ns count.

Parameters

  [in] | p | the packet
  [in] | c | the count

Definition at line 554 of file packet.c.

References ldns_struct_pkt::_header, and ldns_struct_hdr::_nscount.

void ldns_pkt_set_arcount | ( | ldns_pkt * | p,
|  | uint16_t | c
| ) |  |

Set the packet's arcount.

Parameters

  [in] | p | the packet
  [in] | c | the count

Definition at line 560 of file packet.c.

References ldns_struct_hdr::_arcount, and ldns_struct_pkt::_header.

void ldns_pkt_set_querytime | ( | ldns_pkt * | p,
|  | uint32_t | t
| ) |  |

Set the packet's query time.

Parameters

  [in] | p | the packet
  [in] | t | the querytime in msec

Definition at line 566 of file packet.c.

References ldns_struct_pkt::_querytime.

void ldns_pkt_set_answerfrom | ( | ldns_pkt * | p,
|  | ldns_rdf * | r
| ) |  |

Set the packet's answering server.

Parameters

  [in] | p | the packet
  [in] | r | the address

Definition at line 572 of file packet.c.

References ldns_struct_pkt::_answerfrom.

void ldns_pkt_set_timestamp | ( | ldns_pkt * | p,
|  | struct timeval | timeval
| ) |  |

Set the packet's timestamp.

Parameters

  [in] | p | the packet
  [in] | timeval | the timestamp

Definition at line 578 of file packet.c.

References ldns_struct_pkt::timestamp.

void ldns_pkt_set_size | ( | ldns_pkt * | p,
|  | size_t | s
| ) |  |

Set the packet's size.

Parameters

  [in] | p | the packet
  [in] | s | the size

Definition at line 585 of file packet.c.

References ldns_struct_pkt::_size.

void ldns_pkt_set_edns_udp_size | ( | ldns_pkt * | packet,
|  | uint16_t | s
| ) |  |

Set the packet's edns udp size.

Parameters

  [in] | packet | the packet
  [in] | s | the size

Definition at line 591 of file packet.c.

References ldns_struct_pkt::_edns_udp_size.

void ldns_pkt_set_edns_extended_rcode | ( | ldns_pkt * | packet,
|  | uint8_t | c
| ) |  |

Set the packet's edns extended rcode.

Parameters

  [in] | packet | the packet
  [in] | c | the code

Definition at line 597 of file packet.c.

References ldns_struct_pkt::_edns_extended_rcode.

void ldns_pkt_set_edns_version | ( | ldns_pkt * | packet,
|  | uint8_t | v
| ) |  |

Set the packet's edns version.

Parameters

  [in] | packet | the packet
  [in] | v | the version

Definition at line 603 of file packet.c.

References ldns_struct_pkt::_edns_version.

void ldns_pkt_set_edns_z | ( | ldns_pkt * | packet,
|  | uint16_t | z
| ) |  |

Set the packet's edns z value.

Parameters

  [in] | packet | the packet
  [in] | z | the value

Definition at line 609 of file packet.c.

References ldns_struct_pkt::_edns_z.

void ldns_pkt_set_edns_data | ( | ldns_pkt * | packet,
|  | ldns_rdf * | data
| ) |  |

Set the packet's edns data.

Parameters

  [in] | packet | the packet
  [in] | data | the data

Definition at line 615 of file packet.c.

References ldns_struct_pkt::_edns_data.

void ldns_pkt_set_section_count | ( | ldns_pkt * | p,
|  | ldns_pkt_section | s,
|  | uint16_t | x
| ) |  |

Set a packet's section count to x.

Parameters

  [in] | p | the packet
  [in] | s | the section
  [in] | x | the section count

Definition at line 621 of file packet.c.

References ldns_pkt_set_ancount(), ldns_pkt_set_arcount(), ldns_pkt_set_nscount(), ldns_pkt_set_qdcount(), LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_ANY, LDNS_SECTION_ANY_NOQUESTION, LDNS_SECTION_AUTHORITY, and LDNS_SECTION_QUESTION.

void ldns_pkt_set_tsig | ( | ldns_pkt * | p,
|  | ldns_rr * | t
| ) |  |

Set the packet's tsig rr.

Parameters

  [in] | p | the packet
  [in] | t | the tsig rr

Definition at line 642 of file packet.c.

References ldns_struct_pkt::_tsig_rr.

bool ldns_pkt_push_rr | ( | ldns_pkt * | packet,
|  | ldns_pkt_section | section,
|  | ldns_rr * | rr
| ) |  |

push an rr on a packet

Parameters

  [in] | packet | packet to operate on
  [in] | section | where to put it
  [in] | rr | rr to push

Returns
  a boolean which is true when the rr was added

Definition at line 648 of file packet.c.

References ldns_pkt_additional(), ldns_pkt_ancount(), ldns_pkt_answer(), ldns_pkt_arcount(), ldns_pkt_authority(), ldns_pkt_nscount(), ldns_pkt_qdcount(), ldns_pkt_question(), ldns_pkt_set_ancount(), ldns_pkt_set_arcount(), ldns_pkt_set_nscount(), ldns_pkt_set_qdcount(), ldns_rr_list_push_rr(), LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_ANY, LDNS_SECTION_ANY_NOQUESTION, LDNS_SECTION_AUTHORITY, and LDNS_SECTION_QUESTION.

bool 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.

Parameters

  [in] | pkt | packet to operate on
  [in] | sec | where to put it
  [in] | rr | rr to push

Returns
  a boolean which is true when the rr was added

Definition at line 684 of file packet.c.

References ldns_pkt_push_rr(), and ldns_pkt_rr().

bool ldns_pkt_push_rr_list | ( | ldns_pkt * | packet,
|  | ldns_pkt_section | section,
|  | ldns_rr_list * | list
| ) |  |

push a rr_list on a packet

Parameters

  [in] | packet | packet to operate on
  [in] | section | where to put it
  [in] | list | the rr_list to push

Returns
  a boolean which is true when the rr was added

Definition at line 696 of file packet.c.

References ldns_pkt_push_rr(), ldns_rr_list_rr(), and ldns_rr_list_rr_count().

bool ldns_pkt_safe_push_rr_list | ( | ldns_pkt * | pkt,
|  | ldns_pkt_section | sec,
|  | ldns_rr_list * | list
| ) |  |

push an rr_list to a packet, provided the RRs are not already there.

Parameters

  [in] | pkt | packet to operate on
  [in] | sec | where to put it
  [in] | list | the rr_list to push

Returns
  a boolean which is true when the rr was added

Definition at line 708 of file packet.c.

References ldns_pkt_safe_push_rr(), ldns_rr_list_rr(), and ldns_rr_list_rr_count().

bool ldns_pkt_edns | ( | const ldns_pkt * | packet | ) |

returns true if this packet needs and EDNS rr to be sent.

At the moment the only reason is an expected packet size larger than 512 bytes, but for instance dnssec would be a good reason too.

Parameters

  [in] | packet | the packet to check

Returns
  true if packet needs edns rr

Definition at line 720 of file packet.c.

References ldns_pkt_edns_data(), ldns_pkt_edns_do(), ldns_pkt_edns_extended_rcode(), and ldns_pkt_edns_udp_size().

ldns_pkt* ldns_pkt_new | ( | void |  | ) |

allocates and initializes a ldns_pkt structure.

Returns
  pointer to the new packet

Definition at line 732 of file packet.c.

References ldns_struct_pkt::_additional, ldns_struct_pkt::_answer, ldns_struct_pkt::_authority, ldns_struct_pkt::_header, ldns_struct_pkt::_question, LDNS_FREE, LDNS_MALLOC, LDNS_PACKET_QUERY, ldns_pkt_set_aa(), ldns_pkt_set_ad(), ldns_pkt_set_answerfrom(), ldns_pkt_set_cd(), 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_id(), ldns_pkt_set_opcode(), ldns_pkt_set_qr(), ldns_pkt_set_querytime(), ldns_pkt_set_ra(), ldns_pkt_set_rcode(), ldns_pkt_set_rd(), ldns_pkt_set_section_count(), ldns_pkt_set_size(), ldns_pkt_set_tc(), ldns_pkt_set_tsig(), ldns_rr_list_new(), LDNS_SECTION_ADDITIONAL, LDNS_SECTION_ANSWER, LDNS_SECTION_AUTHORITY, LDNS_SECTION_QUESTION, and ldns_struct_pkt::timestamp.

void ldns_pkt_free | ( | ldns_pkt * | packet | ) |

frees the packet structure and all data that it contains.

Parameters

  [in] | packet | The packet structure to free

Returns
  void

Definition at line 784 of file packet.c.

References ldns_struct_pkt::_additional, ldns_struct_pkt::_answer, ldns_struct_pkt::_answerfrom, ldns_struct_pkt::_authority, ldns_struct_pkt::_edns_data, ldns_struct_pkt::_header, ldns_struct_pkt::_question, ldns_struct_pkt::_tsig_rr, LDNS_FREE, ldns_rdf_deep_free(), ldns_rr_free(), and ldns_rr_list_deep_free().

bool ldns_pkt_set_flags | ( | ldns_pkt * | pkt,
|  | uint16_t | flags
| ) |  |

sets the flags in a packet.

Parameters

  [in] | pkt | the packet to operate on
  [in] | flags | ORed values: LDNS_QR| LDNS_AR for instance

Returns
  true on success otherwise false

Definition at line 800 of file packet.c.

References ldns_struct_pkt::_tsig_rr, LDNS_AA, LDNS_AD, LDNS_CD, ldns_native2rdf_int32(), ldns_pkt_free(), ldns_pkt_new(), ldns_pkt_push_rr(), ldns_pkt_set_aa(), ldns_pkt_set_ad(), ldns_pkt_set_answerfrom(), ldns_pkt_set_cd(), ldns_pkt_set_flags(), ldns_pkt_set_qr(), ldns_pkt_set_ra(), ldns_pkt_set_rd(), ldns_pkt_set_tc(), LDNS_QR, LDNS_RA, LDNS_RD, ldns_rdf_clone(), LDNS_RDF_TYPE_INT32, LDNS_RR_CLASS_IN, ldns_rr_free(), ldns_rr_new(), ldns_rr_push_rdf(), ldns_rr_set_class(), ldns_rr_set_owner(), ldns_rr_set_question(), ldns_rr_set_type(), LDNS_RR_TYPE_A, LDNS_RR_TYPE_SOA, LDNS_SECTION_AUTHORITY, LDNS_SECTION_QUESTION, LDNS_STATUS_ERR, LDNS_STATUS_MEM_ERR, LDNS_STATUS_NULL, LDNS_STATUS_OK, ldns_str2rdf_dname(), and LDNS_TC.

ldns_status ldns_pkt_query_new_frm_str | ( | ldns_pkt ** | p,
|  | const char * | rr_name,
|  | ldns_rr_type | rr_type,
|  | ldns_rr_class | rr_class,
|  | uint16_t | flags
| ) |  |

creates a query packet for the given name, type, class.

Parameters

  [out] | p | the packet to be returned
  [in] | rr_name | the name to query for (as string)
  [in] | rr_type | the type to query for
  [in] | rr_class | the class to query for
  [in] | flags | packet flags

Returns
  LDNS_STATUS_OK or a ldns_status mesg with the error

Definition at line 967 of file packet.c.

ldns_status ldns_pkt_ixfr_request_new_frm_str | ( | ldns_pkt ** | p,
|  | const char * | rr_name,
|  | ldns_rr_class | rr_class,
|  | uint16_t | flags,
|  | ldns_rr * | soa
| ) |  |

creates an IXFR request packet for the given name, class.

adds the SOA record to the authority section.

Parameters

  [out] | p | the packet to be returned
  [in] | rr_name | the name to query for (as string)
  [in] | rr_class | the class to query for
  [in] | flags | packet flags
  [in] | soa | soa record to be added to the authority section

Returns
  LDNS_STATUS_OK or a ldns_status mesg with the error

Definition at line 975 of file packet.c.

References ldns_struct_pkt::_tsig_rr, ldns_pkt_free(), ldns_pkt_new(), ldns_pkt_push_rr(), ldns_pkt_set_flags(), ldns_rdf_free(), LDNS_RR_CLASS_IN, ldns_rr_new(), ldns_rr_set_class(), ldns_rr_set_owner(), ldns_rr_set_question(), ldns_rr_set_type(), LDNS_RR_TYPE_A, LDNS_RR_TYPE_IXFR, LDNS_SECTION_AUTHORITY, LDNS_SECTION_QUESTION, LDNS_STATUS_OK, and ldns_str2rdf_dname().

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.

Parameters

  [in] | rr_name | the name to query for
  [in] | rr_type | the type to query for
  [in] | rr_class | the class to query for
  [in] | flags | packet flags

Returns
  ldns_pkt* a pointer to the new pkt

Definition at line 1034 of file packet.c.

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.

adds the SOA record to the authority section.

Parameters

  [in] | rr_name | the name to query for
  [in] | rr_class | the class to query for
  [in] | flags | packet flags
  [in] | soa | soa record to be added to the authority section

Returns
  ldns_pkt* a pointer to the new pkt

Definition at line 1042 of file packet.c.

References LDNS_RR_TYPE_IXFR.

ldns_pkt_type ldns_pkt_reply_type | ( | ldns_pkt * | p | ) |

looks inside the packet to determine what kind of packet it is, AUTH, NXDOMAIN, REFERRAL, etc.

Parameters

  [in] | p | the packet to examine

Returns
  the type of packet

Definition at line 1054 of file packet.c.

References LDNS_PACKET_ANSWER, LDNS_PACKET_NODATA, LDNS_PACKET_NXDOMAIN, LDNS_PACKET_REFERRAL, LDNS_PACKET_UNKNOWN, ldns_pkt_ancount(), ldns_pkt_arcount(), ldns_pkt_get_rcode(), ldns_pkt_nscount(), ldns_pkt_rr_list_by_type(), LDNS_RCODE_NXDOMAIN, ldns_rr_list_deep_free(), LDNS_RR_TYPE_NS, LDNS_RR_TYPE_SOA, and LDNS_SECTION_AUTHORITY.

ldns_pkt* ldns_pkt_clone | ( | ldns_pkt * | pkt | ) |

clones the given packet, creating a fully allocated copy

Parameters

  [in] | pkt | the packet to clone

Returns
  ldns_pkt* pointer to the new packet

Definition at line 1100 of file packet.c.

References ldns_struct_pkt::_additional, ldns_struct_pkt::_answer, ldns_struct_pkt::_authority, ldns_struct_pkt::_question, ldns_pkt_aa(), ldns_pkt_ad(), ldns_pkt_additional(), ldns_pkt_ancount(), ldns_pkt_answer(), ldns_pkt_answerfrom(), ldns_pkt_arcount(), ldns_pkt_authority(), ldns_pkt_cd(), ldns_pkt_edns_data(), ldns_pkt_edns_do(), ldns_pkt_edns_extended_rcode(), ldns_pkt_edns_udp_size(), ldns_pkt_edns_version(), ldns_pkt_edns_z(), ldns_pkt_get_opcode(), ldns_pkt_get_rcode(), ldns_pkt_id(), ldns_pkt_new(), ldns_pkt_nscount(), ldns_pkt_qdcount(), ldns_pkt_qr(), ldns_pkt_querytime(), ldns_pkt_question(), ldns_pkt_ra(), ldns_pkt_rd(), ldns_pkt_set_aa(), ldns_pkt_set_ad(), ldns_pkt_set_ancount(), ldns_pkt_set_answerfrom(), ldns_pkt_set_arcount(), ldns_pkt_set_cd(), ldns_pkt_set_edns_data(), ldns_pkt_set_edns_do(), 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_id(), ldns_pkt_set_nscount(), ldns_pkt_set_opcode(), ldns_pkt_set_qdcount(), ldns_pkt_set_qr(), ldns_pkt_set_querytime(), ldns_pkt_set_ra(), ldns_pkt_set_rcode(), ldns_pkt_set_rd(), ldns_pkt_set_size(), ldns_pkt_set_tc(), ldns_pkt_set_tsig(), ldns_pkt_size(), ldns_pkt_tc(), ldns_pkt_tsig(), ldns_rdf_clone(), ldns_rr_clone(), ldns_rr_list_clone(), and ldns_rr_list_deep_free().

## Variable Documentation

ldns_lookup_table ldns_edns_flags[]

Initial value:
= {
{ 3600, "do"},
{ 0, NULL}
}

EDNS flags.

Definition at line 32 of file packet.c.