#define DESIRED_WINSOCK_VERSION 0x0101
#define MINIMUM_WINSOCK_VERSION 0x0001
// 내부 IP 가져오기CString GetInIpAddress()
{
WSADATA wsadata;
CString strIP = _T("");
if (!WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata))
{
if (wsadata.wVersion >= MINIMUM_WINSOCK_VERSION)
{
HOSTENT *pHostInfo;
IN_ADDR in;
char hostName[128] = { 0,};
gethostname(hostName, 128);
pHostInfo = gethostbyname(hostName);
if (pHostInfo != NULL)
{
int i = 0;
for (; pHostInfo->h_addr_list[i]; i++) {}
memcpy(&in, pHostInfo->h_addr_list[--i],4);
strIP = inet_ntoa(in);
}
}
WSACleanup();
}
return strIP;
}
// 외부 IP 가져오기CString GetIpAddress()
{
WORD wVersionRequested = MAKEWORD(2,0);
WSADATA wsadata;
char hostName[128] = { 0,};
PHOSTENT hostInfo;
CString strIP = _T("");
if (WSAStartup(wVersionRequested, &wsadata) == 0)
{
if (gethostname(hostName, sizeof(hostName)) == 0)
{
if((hostInfo = gethostbyname(hostName)) != NULL)
strIP = inet_ntoa(*(in_addr *)*hostInfo->h_addr_list);
}
WSACleanup();
}
return strIP;
}
#define MINIMUM_WINSOCK_VERSION 0x0001
// 내부 IP 가져오기CString GetInIpAddress()
{
WSADATA wsadata;
CString strIP = _T("");
if (!WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata))
{
if (wsadata.wVersion >= MINIMUM_WINSOCK_VERSION)
{
HOSTENT *pHostInfo;
IN_ADDR in;
char hostName[128] = { 0,};
gethostname(hostName, 128);
pHostInfo = gethostbyname(hostName);
if (pHostInfo != NULL)
{
int i = 0;
for (; pHostInfo->h_addr_list[i]; i++) {}
memcpy(&in, pHostInfo->h_addr_list[--i],4);
strIP = inet_ntoa(in);
}
}
WSACleanup();
}
return strIP;
}
// 외부 IP 가져오기CString GetIpAddress()
{
WORD wVersionRequested = MAKEWORD(2,0);
WSADATA wsadata;
char hostName[128] = { 0,};
PHOSTENT hostInfo;
CString strIP = _T("");
if (WSAStartup(wVersionRequested, &wsadata) == 0)
{
if (gethostname(hostName, sizeof(hostName)) == 0)
{
if((hostInfo = gethostbyname(hostName)) != NULL)
strIP = inet_ntoa(*(in_addr *)*hostInfo->h_addr_list);
}
WSACleanup();
}
return strIP;
}
댓글 없음:
댓글 쓰기