注意不是局域网地址
#是internet地址

解决方案 »

  1.   

    你试试吧!
    const int constBUFFERSIZE = 256;
    static char hostname[constBUFFERSIZE] = "" ; gethostname( hostname, constBUFFERSIZE ) )
    struct hostent * hp ;
    hp = gethostbyname( hostname ) ;
    if ( hp )
    {
         struct in_addr addr ;
         memcpy(&addr.s_addr,(*(hp->h_addr_list)),
                       sizeof(addr.s_addr)) ;
         strcpy( hostname, inet_ntoa(addr) ) ;
    }