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. }



    가끔씩 코딩하다 보면 찾게 되는 소스 ㅎ
 
Posted by 장안동베짱e :