ip 목록 출력

C++ 2012. 11. 9. 13:13

#include <winsock2.h>

#pragma comment (lib, "ws2_32.lib")



WSADATA wsaData;

WORD wVersionRequested = MAKEWORD( 2, 0 );

EXPECT_EQ(WSAStartup(wVersionRequested, &wsaData), 0);

char name[MAX_PATH+1]={0};

EXPECT_EQ(gethostname(name, sizeof(name)), 0);


struct hostent* hostinfo;

hostinfo = gethostbyname(name);

EXPECT_TRUE(hostinfo != NULL);


vector<string> vec;

for (int i=0; hostinfo->h_addr_list[i] != NULL; i++)

{

string ip = inet_ntoa (*(struct in_addr *)hostinfo->h_addr_list[i]);

vec.push_back(ip);

}

WSACleanup();


struct print_helper {

void operator()(string& ip) {

cout << "ip : " << ip << endl;

}

};

for_each(vec.begin(), vec.end(), print_helper());

'C++' 카테고리의 다른 글

[펌] Debugging Tips (1) - .map 파일과 .cod 파일 분석하기  (0) 2013.02.07
zlib 1.2.7 vs 2005 컴파일  (0) 2012.11.22
boost uuid로 sha1 구하기? 샘플  (0) 2012.11.20
_time64로 초단위 로컬 현재 시간  (0) 2012.11.09
윈도우 서비스  (0) 2012.10.11
process kill 프로세스 죽이기  (0) 2012.10.10
pid 구하기  (0) 2012.10.10
현재 프로그램 경로  (0) 2012.10.05