내 PC의 IP 가져오기


로컬 IP를 출력해주는 부분이다.

gethostname() 과 gethostbyname() 두 함수로 로컬 ip 값을 알아 온다.

그리고 특이 한점은 SetAddress() 함수를 이용하면 ip가 거꾸로 찍힌다.

그래서 SetAddress() 안에 ntohl() 함수를 써써 처음부터 뒤집어서 넣는다.

m_addr 은 다이얼로그에 IP Address  변수이다.

결과적으로는 다이얼로그 IP Address 부분에 IP가 입력된다.
PHOSTENT hostinfo
char name[255];
char m_IPAddr[20];
gethostname(name, sizeof(name));
hostinfo = gethostbyname(name);
strcpy(m_IPAddr, inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list));
this->m_strName = m_IPAddr;
m_addr.SetAddress(ntohl(inet_addr(m_IPAddr)));

출처 : http://visu4l.tistory.com/tag/gethostname
크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by shiftkey

2010/07/21 10:28 2010/07/21 10:28
Response
No Trackback , No Comment
RSS :
http://shiftkey.org/rss/response/278


블로그 이미지

Shiftkey가 살아가는 이런 저런 이야기......

- shiftkey

Notices

Archives

Authors

  1. shiftkey

Calendar

«   2012/05   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Site Stats

Total hits:
161242
Today:
23
Yesterday:
243