Thread: detecting connection

  1. #1
    Registered User
    Join Date
    Feb 2005

    Question 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.

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    You could ping the system you want to connect to. Why do you want the application to connect to the internet? Will it connect to a custom server/service or a known one?
    Monday - what a way to spend a seventh of your life

  3. #3
    Registered User
    Join Date
    Feb 2005
    It wonīt connect to any server. It just has to perform some stuff while user is on net. I tried this line:

    if(!system("ping -c 1")) ... //sistem is online

    But itīs quite unelegant (server could be crushed...) and detection is too slow. If someone know for some Linux API function or something similar, that would be great.
    Thanks anyway.

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    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.
    Help populate a c/c++ help irc channel
    server: irc://
    channel: #c

  5. #5
    Registered User
    Join Date
    Sep 2004
    Use the gethostbyname() function, and try to resolve a common domain (Like If it fails, then you can conclude one of the following:
    1) is down (unlikely)
    2) Internet connection is down
    3) Internet connection is up, but DNS server is down

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple forks in one client connection (ftpclient)
    By Dynamo in forum Networking/Device Communication
    Replies: 5
    Last Post: 01-16-2011, 12:41 PM
  2. Replies: 6
    Last Post: 12-19-2008, 05:49 PM
  3. passing a connection to another process.
    By Kinasz in forum Networking/Device Communication
    Replies: 3
    Last Post: 10-09-2004, 05:34 PM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. Detecting (internet) connection status
    By Coder in forum Windows Programming
    Replies: 9
    Last Post: 03-16-2002, 05:14 AM