볼거리, 읽을거리, 놀거리

캐럿보이넷 :: 내(자기 자신) 아이피 알아내기

장안동베짱e 2006. 9. 12. 10:36
  1. void GetLocalIP( char* ip )
  2. {
  3.   WORD wVersionRequested;
  4.   WSADATA wsaData;
  5.   char name[255];
  6.   PHOSTENT hostinfo;
  7.   wVersionRequested = MAKEWORD( 2, 0 );
  8.   if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) {
  9.     if( gethostname ( name, sizeof(name)) == 0) {
  10.       if((hostinfo = gethostbyname(name)) != NULL) {
  11.         strcpy( ip , inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list) );
  12.       }
  13.     }     
  14.     WSACleanup( );
  15.   }
  16. }



    가끔씩 코딩하다 보면 찾게 되는 소스 ㅎ