没有装虚拟机,获取IP地址很正常,但是装上虚拟机之后后,或者有多张网卡的情况,如何来正确IP地址(能够连接公网的那个IP)??高手指点!
解决方案 »
- 在vc++6.0环境下如何实现声音的频率滤波呢?哪位朋友帮帮忙!音频滤波和图像滤波有什么不同呢?
- 为什么我VS2008工具箱里面所有的控件都是灰的?
- 发现我很少在这个版块散分
- ^_^,谁碰到这样的问题,高手进来一下
- 怎样让窗口始终保持在屏幕的最前面啊?
- How can I convert from 'class COleCurrency' to 'const char *'
- 象AutoCAD那样的切换不同视图的程序
- VC6程序如何兼容Websocket协议
- 金山词霸那个大的 主窗口用来显示单词条目和图像的,到底是如何实现的?
- 如何在 MFC AppWizard(dll) 的工程中使用 WM_TIMER
- 单文档使用IE控件的问题
- 对话框程序中建立MDI窗体
BOOL CIocpServerSocket::GetLocalIps(CString &RetIps)
{
vector<char *> vtIps;
// ASSERT you have called WSAStartup to enable the following functions.
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
cout << "WSAStartup failed !" << endl;
return false;
}
char szhn[256];
int nStatus = gethostname(szhn, sizeof(szhn));
if (nStatus == SOCKET_ERROR )
{
cout << "gethostname failed, Error code: " << WSAGetLastError() << endl;
WSACleanup();
return FALSE;
}
HOSTENT *host = gethostbyname(szhn);
if (host != NULL)
{
for ( int i=0; ; i++ )
{
vtIps.push_back( inet_ntoa( *(IN_ADDR*)host-> h_addr_list[i] ) ) ;
if ( host-> h_addr_list[i] + host-> h_length >= host-> h_name )
break;
}
}
for(vector<char *>::iterator it = vtIps.begin(); it != vtIps.end(); it++)
{
RetIps = RetIps + CString(*it) + " ";
}
WSACleanup();
return TRUE;
}