CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    74

    getaddrinfo error

    Below line of code i had found somewhere and tried to find a internet connection is enabled or not but it is giving getaddrinfo error. This was working fine some days before but now giving problem. what could be reason?

    char szAddrASCII[MAX_LOCAL_NAME_LEN];
    ADDRINFO AddrHints, *pAI, *pAddrInfo;


    memset(&AddrHints, 0, sizeof(AddrHints));
    AddrHints.ai_family = PF_UNSPEC;//caller will accept any protocol family
    AddrHints.ai_flags = AI_PASSIVE;

    if(getaddrinfo(szAddrASCII, "10", &AddrHints, &pAddrInfo))
    {
    AfxMessageBox(L"getaddrinfo error %d ", WSAGetLastError() );
    return FALSE;
    }

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: getaddrinfo error

    What kind of problems?

  3. #3
    Join Date
    Mar 2010
    Posts
    74

    Re: getaddrinfo error

    getaddrinfo() is solved but now I am getting scalar deleting destructor(void )error when my below function returns . I have enabled my internet connection but why it executes
    if(memcmp(&(((SOCKADDR_IN6 *)(pAI->ai_addr))->sin6_addr), &BIN_IPV6_ADDR_LOOPBACK, sizeof(BIN_IPV6_ADDR_LOOPBACK)) == 0) line of code ?


    BOOL CNetwork::IsPresent()
    {
    WSADATA WSAData ;
    WSAStartup(MAKEWORD(2,2),&WSAData);


    BOOL bFoundLocalAddr = FALSE;
    char szAddrASCII[MAX_LOCAL_NAME_LEN];
    ADDRINFO AddrHints, *pAI, *pAddrInfo;

    //
    // Get the local host's name in ASCII text.
    //
    if(gethostname(szAddrASCII, MAX_LOCAL_NAME_LEN - 1))
    {
    // Print(TEXT("Error getting local host name, error = %d"), WSAGetLastError());
    AfxMessageBox(L"Error getting local host name, error = %d" , WSAGetLastError());

    return FALSE;
    }

    //
    // To obtain a list of all the local
    // addresses, resolve the local name with getaddrinfo for all

    memset(&AddrHints, 0, sizeof(AddrHints));
    AddrHints.ai_family = PF_UNSPEC;//caller will accept any protocol family
    AddrHints.ai_flags = AI_PASSIVE; //the caller intends to use the returned socket address struc
    int err ;
    if((err=getaddrinfo(szAddrASCII, "10", &AddrHints, &pAddrInfo))!=0)
    {
    // Print(TEXT("getaddrinfo(%hs) error %d"), szAddrASCII, WSAGetLastError());
    //AfxMessageBox(L"getaddrinfo error %d ", WSAGetLastError() );
    printf("errore is %d = %s", err ,gai_strerror(err));
    CString s ;

    s.Format(L"error is %d", err);

    return FALSE;
    }
    //
    // Search the addresses returned.
    // If any of them match the loopback address, then
    // are not connected to an outside network.
    //
    // Note: This will not tell you how many networks you
    // are connected to. If one or more networks are present,
    // then the loopback addresses will not be included in the
    // list returned from getaddrinfo.
    bFoundLocalAddr = TRUE;
    for(pAI = pAddrInfo; pAI != NULL && bFoundLocalAddr; pAI = pAI->ai_next)
    {
    if(pAI->ai_family == PF_INET)
    {
    if(memcmp(&(((SOCKADDR_IN *)(pAI->ai_addr))->sin_addr), &BIN_IPV4_ADDR_LOOPBACK, sizeof(BIN_IPV4_ADDR_LOOPBACK)) == 0)

    bFoundLocalAddr = FALSE;
    }
    else if(pAI->ai_family == PF_INET6)
    {
    if(memcmp(&(((SOCKADDR_IN6 *)(pAI->ai_addr))->sin6_addr), &BIN_IPV6_ADDR_LOOPBACK, sizeof(BIN_IPV6_ADDR_LOOPBACK)) == 0)
    bFoundLocalAddr = FALSE;
    }
    }

    freeaddrinfo(pAddrInfo);

    return bFoundLocalAddr;
    }


    thanks
    Rohit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured