Re: Detecting network and/or inet

new topic     » goto parent     » topic index » view thread      » older message » newer message

Adapted from my previous response eleven years ago. smile

Re: Is this computer connected to the Internet

-- InternetGetConnectedState function 
-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa384702(v=vs.85).aspx 
 
include std/dll.e 
include std/machine.e 
 
constant wininet = open_dll( "wininet.dll" ) 
constant xInternetGetConnectedState = define_c_func( wininet, 
    "InternetGetConnectedState", {C_POINTER,C_LONG}, C_INT ) 
 
ifdef not EU4_1 then 
function sizeof( atom ctype ) 
    return and_bits( ctype, #FF ) 
end function 
end ifdef 
 
public constant 
    INTERNET_CONNECTION_MODEM       = #01, 
    INTERNET_CONNECTION_LAN         = #02, 
    INTERNET_CONNECTION_PROXY       = #04, 
    INTERNET_CONNECTION_MODEM_BUSY  = #08,    -- no longer used 
    INTERNET_RAS_INSTALLED          = #10, 
    INTERNET_CONNECTION_OFFLINE     = #20, 
    INTERNET_CONNECTION_CONFIGURED  = #40, 
$ 
 
public function InternetGetConnectedState() 
     
    atom lpdwFlags = allocate( sizeof(C_POINTER), 1 ) 
    atom dwFlags = 0 
    atom dwReserved = 0 
     
    atom result = c_func( xInternetGetConnectedState, {lpdwFlags,dwReserved} ) 
    dwFlags = peek4u( lpdwFlags ) 
     
    return {result,dwFlags} 
end function 

Example:

include std/utils.e 
include internet.e 
 
sequence result = InternetGetConnectedState() 
sequence status = iff( result[1], "Online", "Offline" ) 
 
printf( 1, "status = %s (flags = #%02x)\n", {status,result[2]} ) 

Output:

status = Online (flags = #12) 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu