char szhostname[128];
CString str;
if( gethostname(szhostname, 128) == 0 )//获得主机名
{
// 获得主机ip地址
struct hostent * phost;
phost = gethostbyname(szhostname);//根据主机名获得IP地址
m_strName=szhostname;
int h_length=4;
for( int j = 0; j<h_length; j++ )
{
CString addr;
if( j > 0 )
str += ".";
addr.Format("%u", (unsigned int)((unsigned char*)phost->h_addr_list[0])[j]);
str += addr;
}
m_strIP=str;
}
CString str;
if( gethostname(szhostname, 128) == 0 )//获得主机名
{
// 获得主机ip地址
struct hostent * phost;
phost = gethostbyname(szhostname);//根据主机名获得IP地址
m_strName=szhostname;
int h_length=4;
for( int j = 0; j<h_length; j++ )
{
CString addr;
if( j > 0 )
str += ".";
addr.Format("%u", (unsigned int)((unsigned char*)phost->h_addr_list[0])[j]);
str += addr;
}
m_strIP=str;
}