Obtain computer name Functions

Source: Internet
Author: User

1 function getcomputername: Obtain the NetBIOS Name of the local computer. This name is read from the registry at system startup. If the local computer is a node on the cluster computer, the name of the cluster virtual server is returned.
Bool getcomputername (lptstr lpbuffer, lpdword lpnsize)
2. The gethostname function obtains the name of the local computer.
Int gethostname (char * Name, int namelen );
3. The gethostbyname function obtains the corresponding "host" (with a name and address flag) from the host name database. Note that there may be multiple hosts, not just one
Struct hostent * far gethostbyname (const char * name)
4. The gethostbyaddr function can obtain the corresponding host (identified by the name and address) from the network address. Note that there may be multiple hosts rather than one
Struct hostent * far gethostbuaddr (const char * ADDR, int Len, int type)
5. Obtain the subnet mask of the computer.
The getadaptersinfo () function obtains the network information of the Local Computer and obtains the subnet mask of the computer.

 

Void ccomputernetbiosnamexdlg: oncomputernetbiosname ()
{
Wsadata;
Wsastartup (makeword (1, 1), & wsadata );
Char buffer [50];
DWORD nsize = strlen (buffer );
Getcomputername (buffer, & nsize );
Setdlgitemtext (idc_computernetbiosname, buffer );
Wsacleanup ();

}

Void ccomputernetbiosnamexdlg: onloadcomputername ()
{
Wsadata;
Wsastartup (makeword (1, 1), & wsadata );
Char name [50];
Gethostname (name, strlen (name ));
Setdlgitemtext (idc_loadcomputername, name );
Wsacleanup ();
 
}

Void ccomputernetbiosnamexdlg: oncomputer ()
{
Wsadata;
Wsastartup (makeword (1, 1), & wsadata );
Char name [50];
Gethostname (name, strlen (name ));
Struct hostent * phost;
Phost = gethostbyname (name );
Setdlgitemtext (idc_computer, phost-> h_name );
For (INT I = 0; phost! = NULL & phost-> h_addr_list [I]! = NULL; I ++)
{

Cstring STR;
STR = inet_ntoa (* (struct in_addr *) phost-> h_addr_list [I]);
M_list.addstring (STR );
}
Wsacleanup ();
 
}

Void ccomputernetbiosnamexdlg: ongethostbuaddr ()
{
Wsadata;
Wsastartup (makeword (1, 1), & wsadata );
DWORD dwipaddr;
Dwipaddr = inet_addr ("192.168.0.2 ");
Hostent * PHT;
PHT = gethostbyaddr (lpstr) & dwipaddr, 4, af_inet );
MessageBox (PHT-> h_name );
Wsacleanup ();
}

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.