This commit is contained in:
2013-07-20 23:27:27 +00:00
parent 3341a87697
commit 8024ab7e8e

52
Common/IPInfos.cpp Normal file
View File

@@ -0,0 +1,52 @@
// IPInfos.cpp: implementation of the CIPInfos class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "IPInfos.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define CHAR_BUFFER_SIZE 255
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIPInfos::CIPInfos()
{
}
CIPInfos::~CIPInfos()
{
}
int CIPInfos::GetLocalIPCount()
{
char csHostName[CHAR_BUFFER_SIZE];
LPHOSTENT pHost;
int i;
gethostname(csHostName, CHAR_BUFFER_SIZE);
pHost = gethostbyname(csHostName);
for (i = 0; pHost->h_addr_list[i] != NULL; i++) {}
return i;
}
CString CIPInfos::GetLocalIP(int nIndex)
{
char csHostName[CHAR_BUFFER_SIZE];
LPHOSTENT pHost;
gethostname(csHostName, CHAR_BUFFER_SIZE);
pHost = gethostbyname(csHostName);
return CString(inet_ntoa(*(struct in_addr*)pHost->h_addr_list[nIndex]));
}