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 gethostbyaddr(). 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 initialize 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:
Alternatively, a hard coded domain name can be set using CDL. The boolean CYGPKG_NS_DNS_DOMAINNAME enables 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.