[这个贴子最后由x86在 2005/04/18 06:32pm 第 2 次编辑]
#pragma comment (lib,"Ws2_32.lib")
#include
#include
int WSA_return;
WSADATA WSAData;
HOSTENT *host_entry;
char host_name[256];
char host_address[256];
int main()
{
WSA_return=WSAStartup(MAKEWORD(1,1),&WSAData);
if(WSA_return==0)
{
gethostname(host_name,256);
host_entry=gethostbyname(host_name);
if(host_entry!=0)
{
wsprintf(host_address,"%d.%d.%d.%d",
(host_entry->h_addr_list[0][0]&0x00ff),
(host_entry->h_addr_list[0][1]&0x00ff),
(host_entry->h_addr_list[0][2]&0x00ff),
(host_entry->h_addr_list[0][3]&0x00ff));
MessageBox(NULL,host_address,host_name,MB_OK);
}
}
WSACleanup();
return 0;
} |