Chapter 45. dns, Dns api – Comtrol eCos User Manual
Page 597

Chapter 45. DNS
DNS API
The DNS client uses the normal BSD API for performing lookups:
gethostbyname()
and
gethostbyaddr()
.
There are a few restrictions:
•
Only IPv4 is supported, ie IPv6 addresses cannot be looked up.
•
If the DNS server returns multiple authoritive records for a host name, the hostent will only contain a record for
the first entry.
•
The code has been made thread safe. ie multiple threads may call
gethostbyname()
without causing problems
to the hostent structure returned. What is not safe is one thread using both
gethostbyname()
and
gethost-
byaddr()
. A call to one will destroy the results from the previous call to the other function.
To initialise the DNS client the following function must be called:
#include
<
network.h
>
int cyg_dns_res_init(struct in_addr *dns_server)
where dns_server is the address of the DNS server the client should query. On Error this function returns -1,
otherwise 0 for success. If lookups are attemped before this function has been called, they will fail and return
NULL.
A default, hard coded, server may be specified in the CDL option
CYGDAT_NS_DNS_DEFAULT_SERVER
. The use of
this is controlled by
CYGPKG_NS_DNS_DEFAULT
. If this is enabled,
init_all_network_interfaces
will initial-
ize the resolver with the hard coded address. The DHCP client or user code my override this address by calling
cyg_dns_res_init
again.
The DNS client understands the concepts of the target being in a domain. By default no domain will be used. Host
name lookups should be for fully qualified names. The domain name can be set and retrieved using the functions:
int getdomainname(char *name, size_t len);
int setdomainname(const char *name, size_t len);
Alternatively, a hard coded domain name can be set using CDL. The boolean
CYGPKG_NS_DNS_DOMAINNAME
en-
ables this and the domain name is taken from
CYGPKG_NS_DNS_DOMAINNAME_NAME
.
Once set, the DNS client will first perform a lookup with the domain name appended. If this fails it will then
perform a second lookup without the appended domain name.
493