The Internet uses IP addresses for communication, but generally for human and easy memory, defines a set of domain names and a mechanism for mapping domain names to IP addresses. The Domain name collection forms a hierarchy that can be represented as a tree, the nodes of the tree represent the domain name, and the path to the root forms the domain name. Subtree is called subdomain, the first level domain name includes com/edu/gov/org/net and so on, the first level domain name includes two level domain name, for example Cmu.edu, once an organization obtains a two level domain name, then he can create any new domain name in this subdomain.
The internet defines the IP-to-domain mapping, which was done manually by a HOSTS.TXT text file in 1988. Later, this mapping was maintained by distributing database DNS around the world. The DNS database consists of thousands of host entry structures (host entry structure), each of which defines a mapping between a set of domain names and a set of IP addresses. You can assume that each host entry is an equivalent class of domain name and IP address.
The following is the composition code for the host entry structure:
struct Hostent {char *h_name; Official domain name Char **h_aliases; A series of aliases int h_addrtype; Host address type int h_length; The length of the address, in bytes, of Char **h_addr_list; Address};
The internet can retrieve arbitrary host entries from the DNS database by invoking the gethostbyname and GETHOSTBYADDR functions.
Introduction to the Internet Domain Name System (DNS)