kyuseo의 게임 프로그래밍
내 컴퓨터의 아이피 주소 (IP Address)를 얻는 소스코드 본문
개요.. |
내 컴퓨터의 아이피 주소 (IP Address)를 얻는 소스코드를 소개 합니다
소스코드 |
함수
CString GetMyIP() { CString ipAddr;
WSADATA wsaData; WORD wVersionRequested = MAKEWORD( 2, 0 );
if( WSAStartup( wVersionRequested, &wsaData ) == 0 ) { char name[256];
if( gethostname( name, sizeof( name ) ) == 0 ) { PHOSTENT hostinfo = gethostbyname( name );
if( hostinfo != NULL) { ipAddr = inet_ntoa( *( struct in_addr* ) *hostinfo->h_addr_list ); } }
WSACleanup(); }
return ipAddr; } |
사용예
CString s = GetMyIP();
|