In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
The direct use of IP addresses in the client will have great disadvantages. Once the IP address changes (the IP address will often change), the client software will show a problem.
The use of the domain name will be much more convenient, the registered domain name will always belong to me as long as it is renewed every year, and the domain name resolution can be modified when changing the IP address, which will not affect the normal use of the software.
There is no specific explanation in this section on domain name registration, domain name resolution, host files, DNS server and so on. Please fill it in by yourself. This section focuses on how to use domain names.
Obtain IP address through domain name
The domain name is only a mnemonic of the IP address, the goal is to facilitate memory, after the domain name can not find the destination computer, the domain name must be converted into an IP address before communication.
The gethostbyname () function can accomplish this transformation, and its prototype is:
Struct hostent * gethostbyname (const char * hostname)
Hostname host name, that is, the domain name. When using this function, you only need to pass the domain name string and go to the IP address corresponding to the domain name. The destination address information is loaded into the hostent construct, which is defined as follows:
Struct hostent {char * html; / / official name char * * hackers; / / alias list int hobbies addrtype; / / host address type int hobbies; / / address lenght char * * hobbies addrlistings; / / address list}
As you can see from this structure, not only go to the IP address, but also other information, the reader only needs to pay attention to the original member h_addr_list. The following is a clarification of the members:
H_name: official domain name (Official domain name). The official domain name represents a home page, but in practice, the domain names of some famous companies are not registered with the official domain name.
H_aliases: alias, you can visit the unified host through multiple domain names. Unified IP addresses can be bound to multiple domain names, so you can specify other domain names in addition to future domain names.
H_addrtype:gethostbyname () supports not only IPv4 but also IPv6. You can get the address family (address type) information of the IP address through this member. IPv4 corresponds to AF_INET,IPv6 and corresponds to AF_INET6.
H_length: keep the length of the IP address. The length of IPv4 is 4 bytes, and the length of IPv6 is 16 bytes.
H_addr_list: this is the most important member. The member keeps the IP address of the domain name as an integer. For servers with more users, multiple IP addresses can be assigned to a unified domain name, and multiple servers can be applied to stop load balancing.
The composition of the hostent constructor variable is shown in the following figure:
The following code mainly demonstrates the use of gethostbyname () and illustrates the characteristics of the hostent construct:
# include # pragma comment (lib, "ws2_32.lib") int main () {WSADATA wsaData; WSAStartup (MAKEWORD (2,2), & wsaData); struct hostent * host = gethostbyname ("www.baidu.com"); if (! host) {puts ("Get IP address error!"); system ("pause"); exit (0);} / / alias for (int item0; host- > haliases [I] ) {printf ("Aliases% d:% s\ n", iTun1, host- > h _ aliases [I]);} / / address type printf ("Address type:% s\ n", (host- > h_addrtype==AF_INET)? "AF_INET": "AF_INET6"); / / IP address for (int item0; host- > html addrList [I]; iSum +) {printf ("IP addr% d:% s\ n", iTun1, inet_ntoa (* (struct in_addr*) addrList [I]));} system ("pause"); return 0;}
Operational consequences:
Aliases 1: www.baidu.com
Address type: AF_INET
IP addr 1: 61.135.169.121
IP addr 2: 61.135.169.125
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.