DNS sock API

Sock DNS client. More...

Detailed Description

Files

file  dns.h
 DNS sock definitions.
 

Data Structures

struct  sock_dns_hdr_t
 DNS internal structure. More...
 

Functions

int sock_dns_query (const char *domain_name, void *addr_out, int family)
 Get IP address for DNS name. More...
 

Variables

sock_udp_ep_t sock_dns_server
 global DNS server endpoint
 

DNS defines

#define DNS_TYPE_A   (1)
 
#define DNS_TYPE_AAAA   (28)
 
#define DNS_CLASS_IN   (1)
 
#define SOCK_DNS_PORT   (53)
 
#define SOCK_DNS_RETRIES   (2)
 
#define SOCK_DNS_MAX_NAME_LEN   (64U) /* we're in embedded context. */
 
#define SOCK_DNS_QUERYBUF_LEN   (sizeof(sock_dns_hdr_t) + 4 + SOCK_DNS_MAX_NAME_LEN)
 

Function Documentation

int sock_dns_query ( const char *  domain_name,
void *  addr_out,
int  family 
)

This function will synchronously try to resolve a DNS A or AAAA record by contacting the DNS server specified in the global variable sock_dns_server.

By supplying AF_INET, AF_INET6 or AF_UNSPEC in family requesting of A records (IPv4), AAAA records (IPv6) or both can be selected.

This fuction will return the first DNS record it receives. IF both A and AAAA are requested, AAAA will be preferred.

Note
addr_out needs to provide space for any possible result! (4byte when family==AF_INET, 16byte otherwise)
Parameters
[in]domain_nameDNS name to resolve into address
[out]addr_outbuffer to write result into
[in]familyEither AF_INET, AF_INET6 or AF_UNSPEC
Returns
0 on success
!=0 otherwise