Client-side detection of established connection
Posted: Thu Sep 29, 2011 4:01 pm
Hi All.
I'm new with OpenVPN and possibly asking well-known things, but i could not find the solution.
I am developing database application which uses VPN connection with database server. (both running Windows)
I whish to automate VPN connetcion at application startup. When VPN connection is established i need to open connection with DB server from my application. Everything works fine except one issue: I don't want to force users to push two different buttons on app's login window (Connect VPN and Connect DB).
The issue is with understanding of established VPN connection.
When user press login button I'm calling openvpv.exe (i'm using CreateProcess function). The connection with VPN server may take unpredictable time and i don't know when i can try to start database connection. So i need to detect if VPN connection is established before trying to open DB connection in my application.
The question is - how to understand that VPN connection has been established?
I see 3 ways to do this:
1. Force OpenVPN to perform some specific action after establishing connection with server (Send any signal to my application, for example run windows batch file)
2. Loop connection testing function in application with some timeout before trying to connect database. (I tried to do this but without any result. It seems that Ws2_32.dll function gethostbyaddr fails to resolve host infomation)
3. Ask the state of OpenVPN virtual TAP interface. (But i don't know how to understand which interface is used by OpenVPN from my application)
Thanks.
I'm new with OpenVPN and possibly asking well-known things, but i could not find the solution.
I am developing database application which uses VPN connection with database server. (both running Windows)
I whish to automate VPN connetcion at application startup. When VPN connection is established i need to open connection with DB server from my application. Everything works fine except one issue: I don't want to force users to push two different buttons on app's login window (Connect VPN and Connect DB).
The issue is with understanding of established VPN connection.
When user press login button I'm calling openvpv.exe (i'm using CreateProcess function). The connection with VPN server may take unpredictable time and i don't know when i can try to start database connection. So i need to detect if VPN connection is established before trying to open DB connection in my application.
The question is - how to understand that VPN connection has been established?
I see 3 ways to do this:
1. Force OpenVPN to perform some specific action after establishing connection with server (Send any signal to my application, for example run windows batch file)
2. Loop connection testing function in application with some timeout before trying to connect database. (I tried to do this but without any result. It seems that Ws2_32.dll function gethostbyaddr fails to resolve host infomation)
3. Ask the state of OpenVPN virtual TAP interface. (But i don't know how to understand which interface is used by OpenVPN from my application)
Thanks.