InternetAttemptConnect

This is a discussion on InternetAttemptConnect within the C++ Programming forums, part of the General Programming Boards category; Whats the reason that if i unplug my internet cable it still returns ERROR_SUCCESS and prints out "Internet available... Code: ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    795

    InternetAttemptConnect

    Whats the reason that if i unplug my internet cable it still returns ERROR_SUCCESS and prints out "Internet available...

    Code:
    #include <cstdio>
    #include <windows.h>
    #include <wininet.h>
    
    
    int main()
    {
       if(InternetAttemptConnect(0) == ERROR_SUCCESS) printf("\nInternet available...\n");
       else printf("Internet unavailable.\n");
    
       return 0;
    }
    Ps i should have posted it in the networking forum. Feel free to deplace it, thanks!
    Compiler MSVC++ 2013 with Code::Blocks.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Whats the reason that if i unplug my internet cable it still returns ERROR_SUCCESS and prints out "Internet available...

    Not sure. MSDN doesn't provide much detail about how it works. If you're using router and only disconnecting it from the line going out to the internet that might make sense, as your computer would still be able to detect it's IP address, causing InternetAttemptConnect to assume there is a connection. At any rate, there are probably other ways to do this. You could first check that you have an active IP address other than the loop-back, and if so, attempt to open a socket with the destination set to that IP address. I haven't tested it out though, but I'm pretty sure it'd work.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    795
    Thanks Sebastiani!

    Not much use for this function then.
    Compiler MSVC++ 2013 with Code::Blocks.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    It is weird that it takes an unused parameter, though. Is that for future compatibility, or current undocumented usage?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    795
    Code:
        hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL,0);
        if(hInternet == NULL)printf("Internet unavailable.\n");
    Same story with InternetOpen(). Cant check if its NULL.
    Compiler MSVC++ 2013 with Code::Blocks.

  6. #6
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    It is weird that it takes an unused parameter, though. Is that for future compatibility, or current undocumented usage?
    Probably neither. The argument isn't referenced XP through 7 except to check against 0, and given that the function is mainly intended for dial-up usage (going by the remarks), probably never will be. But who knows.

    Same story with InternetOpen(). Cant check if its NULL.
    InternetOpen and InternetConnect just set up state, no attempts are made until HttpSendRequest or an equivalent is called. I use InternetCheckConnection with a url and the FLAG_ICC_FORCE_CONNECTION flag to check connectedness, and it seems to work correctly.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21