Search code examples
c++cwininet

How to check for internet availability in c++


I wrote one small function to check internet connection availability

void cis()
{
    if(InternetCheckConnection(NULL,FLAG_ICC_FORCE_CONNECTION,0))
    {
        cout << "internet alive";
    }
}

I'm using WinInet.h for InternetCheckConnection(). Now the problem is that I get the following linker error:

[Linker error] undefined reference to `_imp__InternetCheckConnectionA@12'

I am using DevC++ for my project. Any ideas on how to fix this linker problem or any other ideas to check for an active internet connection?


Solution

  • Its a linker error. as per the documentation you need to use wininet library. adding -lwininet in makefile may work.