C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-06-2005, 05:11 PM   #1
zly
Registered User
 
Join Date: Feb 2005
Posts: 2
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.
zly is offline   Reply With Quote
Old 02-09-2005, 10:34 AM   #2
Hamster without a wheel
 
iain's Avatar
 
Join Date: Aug 2001
Posts: 1,385
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
iain is offline   Reply With Quote
Old 02-13-2005, 12:06 PM   #3
zly
Registered User
 
Join Date: Feb 2005
Posts: 2
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 www.google.com")) ... //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.
zly is offline   Reply With Quote
Old 02-13-2005, 01:09 PM   #4
Obsessed with C
 
chrismiceli's Avatar
 
Join Date: Jan 2003
Posts: 501
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://irc.efnet.net
channel: #c
chrismiceli is offline   Reply With Quote
Old 02-14-2005, 03:03 PM   #5
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 3,020
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
bithub is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a router, can I "dedicate" bandwith to a certain connection as needed? indigo0086 Tech Board 6 12-19-2008 05:49 PM
multiple forks in one client connection (ftpclient) Dynamo Networking/Device Communication 3 07-09-2008 02:26 PM
passing a connection to another process. Kinasz Networking/Device Communication 3 10-09-2004 05:34 PM
Headers that use each other nickname_changed C++ Programming 7 10-03-2003 04:25 AM
Detecting (internet) connection status Coder Windows Programming 9 03-16-2002 05:14 AM


All times are GMT -6. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22