The easiest workaround that comes to my mind is trying to connect to a known network or host (such as google) and grabbing the socket errors if any.
İf a socket error occurs, simply check the errno for error number: ENETUNREACH on Linux, and WSAGetLastError() for WSAEHOSTUNREACH on Windows.