detecting connection

This is a discussion on detecting connection within the Linux Programming forums, part of the Platform Specific Boards category; First, I want to apologise about my english, itīs realy bad. I hope that it will be clear enought for ...

detecting connection

First, I want to apologise about my english, itīs realy bad. I hope that it will be clear enought for understending essence of my problem. Iīm a new in Linux programming and Iīm trying to improve that. My little program has to detect whether is system connected on the interner or not. I supose that there is simple solution (in Win there is RAS library, but in Lin I donīt know where to look). I would appreciate if someone could answer me. Thanks.

Use sockets to try and make a connec()tion to an outside server. You could I guess check to see if they have everything set up for internet, but that doesn't mean it is going to work, so you will have to see if you can reach outside of the system.

Use the gethostbyname() function, and try to resolve a common domain (Like yahoo.com). If it fails, then you can conclude one of the following:
1) yahoo.com is down (unlikely)
2) Internet connection is down
3) Internet connection is up, but DNS server is down