1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sal.hxx"
26 #ifdef _MSC_VER
27 #pragma warning( disable: 4668 )
28 #endif
29 
30 #include <sal/types.h>
31 
32 #define WIN32_LEAN_AND_MEAN
33 #include <windows.h>
34 #include <wininet.h>
35 
36 #ifdef UNICODE
37 #define _UNICODE
38 #endif
39 #include <tchar.h>
40 #ifdef __MINGW32__
41 #include <excpt.h>
42 #endif
43 
44 #define elementsof(a) (sizeof(a)/sizeof((a)[0]))
45 
46 // #i71984
hasInternetConnection()47 extern "C" sal_Bool SAL_CALL hasInternetConnection()
48 {
49 	DWORD	dwFlags;
50 	TCHAR	szConnectionName[1024];
51 
52 #ifdef __MINGW32__
53         jmp_buf jmpbuf;
54         __SEHandler han;
55         if (__builtin_setjmp(jmpbuf) == 0)
56         {
57         han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER);
58 #else
59 	__try {
60 #endif
61 	BOOL fIsConnected = InternetGetConnectedStateEx(
62 		&dwFlags,
63 		szConnectionName,
64 		elementsof(szConnectionName),
65 		0 );
66 
67 	return fIsConnected ? sal_True : sal_False;
68 
69 #ifdef __MINGW32__
70         }
71         else return sal_False;
72         han.Reset();
73 #else
74 	} __except( EXCEPTION_EXECUTE_HANDLER )	{
75 		return sal_False;
76 	}
77 #endif
78 }
79