From 8024ab7e8eed5e5a75b0c905cd85ffb74b834551 Mon Sep 17 00:00:00 2001 From: mjjo Date: Sat, 20 Jul 2013 23:27:27 +0000 Subject: [PATCH] --- Common/IPInfos.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Common/IPInfos.cpp diff --git a/Common/IPInfos.cpp b/Common/IPInfos.cpp new file mode 100644 index 0000000..b951471 --- /dev/null +++ b/Common/IPInfos.cpp @@ -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])); +} \ No newline at end of file