로컬 IP주소를 얻을 수 있는 함수입니다.
CString 타입으로 _T("xxx.xxx.xxx.xxx")와 같이 반환합니다.
#include <afxsock.h>
CString GetIPAddress()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255];
CString ip; // 여기에 lcoal ip가 저장됩니다.
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 2, 0 );
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);
}
}
WSACleanup( );
}
return ip;
}
'개발이야기 > MFC' 카테고리의 다른 글
| 뮤텍스를 이용한 프로그램 중복실행 방지 (0) | 2012.05.18 |
|---|---|
| 일정 날짜 기준 로그파일 제거 (1) | 2012.05.17 |
| 유니코드 ↔ 안시 변환함수 (0) | 2012.05.16 |
| 폴더선택 다이얼로그와 초기폴더경로 설정 (0) | 2012.05.15 |
| MFC Control 오픈소스 모음 (0) | 2012.05.13 |