Loading...
Searching...
No Matches
DNS message parser and composer

Parsing and composition of DNS messages. More...

Detailed Description

Parsing and composition of DNS messages.

Modules

 DNS message parsing and composition configuration
 

Files

file  msg.h
 Definitions for parsing and composition of DNS messages.
 

Data Structures

struct  dns_hdr_t
 DNS internal structure. More...
 

Functions

size_t dns_msg_compose_query (void *dns_buf, const char *domain_name, uint16_t id, int family)
 Composes a DNS query message.
 
int dns_msg_parse_reply (const uint8_t *buf, size_t len, int family, void *addr_out, uint32_t *ttl)
 Parses a DNS response message.
 

Function Documentation

◆ dns_msg_compose_query()

size_t dns_msg_compose_query ( void *  dns_buf,
const char *  domain_name,
uint16_t  id,
int  family 
)

Composes a DNS query message.

The query will request an A or AAAA IN record for domain_name depending on family:

  • When family is AF_INET or AF_UNSPEC a query for an A record will be added
  • When family is AF_INET6 or AF_UNSPEC a query for an AAAA record will be added
Parameters
[out]dns_bufA buffer of length CONFIG_DNS_MSG_LEN
[in]domain_nameThe domain name to query.
[in]idThe ID for the query.
[in]familyEither AF_UNSPEC, AF_INET, or AF_INET6. Determines the address records for domain_name queried.
Returns
Size of the composed query in bytes.

◆ dns_msg_parse_reply()

int dns_msg_parse_reply ( const uint8_t *  buf,
size_t  len,
int  family,
void *  addr_out,
uint32_t *  ttl 
)

Parses a DNS response message.

Parameters
[in]bufThe message to parse.
[in]lenLength of buf.
[in]familyThe address family used to compose the query for this response (see dns_msg_compose_query())
[out]addr_outThe IP address returned by the response.
[out]ttlThe live time of the entry in seconds
Returns
Length of the addr_out on success.
-EBADMSG, when an address corresponding to family can not be found in buf.