⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cminetaddress.cpp

📁 Soul的源代码,类似于劲舞团之类的游戏
💻 CPP
字号:
#include <MatrixCore/System/CMString.h>
#include "CMInetAddress.h"
#include <tchar.h>
using namespace MatrixCore::Network;

CMInetAddress::CMInetAddress()
{

}

CMInetAddress::~CMInetAddress()
{
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	GetHostAddress()
//	DESC :: 泅犁 哪腔磐狼 IP林家甫 府畔茄促.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CMString CMInetAddress::GetHostAddress()
{
	WSADATA wsaData;

	//扩加 2.0滚怜 荤侩
	if( WSAStartup( MAKEWORD( 2, 2 ), &wsaData ) != 0 )
		return NULL;

	PHOSTENT hostInfo;
	char name[512];

	if( gethostname( name, sizeof( name ) ) != 0 )	return CMString( _T( "Cannot getting host name." ) );
	if( ( hostInfo = gethostbyname( name ) ) == 0 ) return CMString( _T( "Cannot getting host from name." ) );

	WSACleanup();

	return CMString( inet_ntoa( *( struct in_addr * )*hostInfo->h_addr_list ) );
}

CMString CMInetAddress::GetHostName()
{
	char name[512];

	if( gethostname( name, sizeof( name ) ) != 0 )	return CMString( _T( "Cannot getting host name." ) );

	return CMString( name );
}

CMString CMInetAddress::GetHostByName( CMString& name )
{
	HOSTENT* hostent;
	char* ip;

	hostent = ::gethostbyname( name.getBuffer() );
	if( hostent != 0 )
	{
		ip = inet_ntoa( *( struct in_addr* )*hostent->h_addr_list );

		return CMString( ip );
	}

	return CMString( _T( "" ) );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -