I have been trying to check Internet connection but all ways I have tried have failed. Some example code would be great, or the package to use. Thanks very much.
What compiler and OS?
Linux, and it is using gcc to compile it.
The easiest way is to use a socket to connect to a known stable server. If it succeeds you now know you've got an internet connection. If it fails, you can use error messages or assumptions to determine the status.