getpeername() Retrieves the name of the peer connected to the specified socket. 
getsockname() Retrieves the local address to which the specified socket is bound. 

解决方案 »

  1.   

    //这段代码能获得你机器上的所有IP对于多穴主机相当管用。 CString strIp[];   
     int nCount = 0;
        char name[255];
    if( gethostname ( name, sizeof(name)) == 0)
    {
    PHOSTENT hostinfo;
    hostinfo = gethostbyname(name);
    for(int  i = 0; hostinfo!= NULL && hostinfo->h_addr_list[i] != NULL; i++ )
    {        
    strIp[i] = inet_ntoa (*(struct in_addr *)hostinfo->h_addr_list[i]);
    nCount++;
    }
    }