Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all

i wrote a code in sample application.
C++
char            szHostName[255];
int iEc   = -1;
addrinfo* pAdInfo = NULL;

                // get the local hostname
if( gethostname(szHostName, 255) == SOCKET_ERROR )
{
    return ;
}

CString sTmp(szHostName);
::AfxMessageBox(sTmp);
iEc = getaddrinfo(szHostName, NULL, NULL, &pAdInfo);
if( S_OK == iEc )
{
    sTmp.Format(_T("family[%d]"),pAdInfo->ai_family);
    ::AfxMessageBox(sTmp);
}


It gives different family in window 7 and different family in window XP
win 7 : AF_INET6
win xp; AF_INET

my question how can i can get the same ip4 in both.

thankyou
Posted

1 solution

Pass an addrinfo structure to specify the type (IPv4 or IPv6). See the getaddrinfo()[^] function and the addrinfo[^] structure. When passing no addrinfo structure or setting the ai_family member to AF_UNSPEC, the returned family type is IPv6 when it is installed (always with Vista and later).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900