#include <winsock2.h>#pragma comment(lib,"ws2_32.lib")main()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 ); if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{ if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
}
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip;
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 ); if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{ if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
}
解决方案 »
- opengl es 1.x sdk PC Emulation不能在mfc工程中运行吗
- RicheditCtrl怎么添加滚动条
- 请问怎样得到一个自1970年零点以来经过的秒数,并且如何将其转化为“YYYY-mm-dd hh:mm:ss"的时间格式?
- 高手来解释以下!
- 在声卡未提供Mixer(混音器)驱动程序情况下,如何同步录下系统输出的所有有声音及所有音源输入?
- 求救:关于vc利用msxml读取xml文档时的问题
- 快过年了,有一个问题大家积极的讨论一下吧:把位图转换成矢量图的算法讨论及可行性分析。顺便散点儿分喽!
- 如何给一个窗口发一个模拟按键alt的消息?或者用什么函数?
- 感谢zswzwy的例子,不过我只有10分了,不要意思:)
- 又遇难题了,求教高高手,下面三行的逆转换怎弄????()
- 控件操作
- 如何把CString类型转换为const char*类型?在线等待!
#pragma comment(lib,"ws2_32")
BOOL CPlayerTypeDlg::GetLocalIP(BYTE &nField00, BYTE &nField01, BYTE &nField02, BYTE &nField03)
{
WORD wVersionRequested;
WSADATA wsaData;
char szHostName[128];
wVersionRequested=MAKEWORD(2,0); if(WSAStartup(wVersionRequested,&wsaData)==0)
{
if(gethostname(szHostName,128)==0)
{
struct hostent* pHost;
int i; pHost=gethostbyname(szHostName);
for(i=0;pHost!=NULL && pHost->h_addr_list[i]!=NULL;i++)
{
nField00=(unsigned int)((unsigned char*)pHost->h_addr_list[i])[0];
nField01=(unsigned int)((unsigned char*)pHost->h_addr_list[i])[1];
nField02=(unsigned int)((unsigned char*)pHost->h_addr_list[i])[2];
nField03=(unsigned int)((unsigned char*)pHost->h_addr_list[i])[3];
}
}
WSACleanup();
}
if ((nField00==0) && (nField02==0) && (nField01==0) && (nField03==0))
return false;
else
return true;
}