GetHostByName call fails under windows

Source: Internet
Author: User
The gethostbyname () function belongs to the Winsock API library, and you must call the WSAStartup function before using the Winsock API.
Only the function returns successfully (indicating that the application has successfully established a connection with the Winsock library),
The application can call functions in other Windows Sockets DLLs. When the program is about to end, you must also call the WSACleanup function to clean up so that it frees up the resources it occupies.
The WSACleanup function is used to end the use of Windows Sockets DLLs.

WSAStartup and WSACleanup
WSAStartup should be used in pairs with wsacleanup, the function of WSAStartup is to initialize Winsock Dll,wsacleanup to unbind the socket library and release the system resources occupied by the socket library.

Under Windows, the socket is implemented as a DLL. Inside the DLL maintains a counter, only the first call to WSAStartup to actually load the DLL, the subsequent call is simply to increase the counter, and the function of the WSACleanup function is just the opposite, each call to make the counter minus 1, when the counter is reduced to 0 o'clock, DLL is unloaded from memory! So how many times you call WSAStartup, the WSACleanup should be called the corresponding number of times.

GetHostByName call fails under windows

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.