VC uses gethostbyname to resolve the Domain Name

Source: Internet
Author: User

VC uses gethostbyname to resolve the Domain Name
The source code is later. The source code uses MFC and you need to import the # include "winsock2.h" header file. You need to import ws2_32.lib to modify this Code and make it into other applications.
The source code is as follows:
Int status;
Wsadata;
Char sztemp1 [80];
Struct in_addr ADDR;
If (status = wsastartup (makeword (1, 1), & wsadata) = 0)
{
MessageBox (wsadata. szdescription, wsadata. szsystemstatus, mb_ OK );
}
Else {
Sprintf (sztemp1, "% d is the Err", status );
MessageBox (sztemp1, "error", mb_ OK );
}
Phostent Phe;

PHE = gethostbyname ("www.g.cn ");
If (PHE = NULL ){
Char sztemp [200];
Sprintf (sztemp, "% d is the error. Make sure '% s' is listed in the hosts file.", wsagetlasterror (), "www.g.cn ");
MessageBox (sztemp, "gethostbyname () failed.", mb_ OK );
Return;
}
Else
{
ADDR. s_addr = * (u_long *) phe-> h_addr_list [0];
MessageBox (inet_ntoa (ADDR ));
}
After execution, a dialog box is displayed, showing the address of the current domain name:

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.