You are not logged in.
Hello. I've never written a daemon before, but I'm pretty comfortable with C/C++, and I wanted to write a daemon that would react when my system lost or gained internet access. Does anyone have any ideas as to how to start?
I know this is basically a terrible question, but perhaps someone could point me to events or signals that I could use to get started? Or perhaps another program that does something similar? Thanks a lot for any help.
Offline
What about a ping to a web site, for example opendns.org?
ping -c 4 www.opendns.org
This would send 4 ping messages to the server.
Offline
Thanks for the idea, but that's gonna have to happen on a per-program basis and is pretty slow/heavy on the network. What I want is something like the network daemon/notification thingy in Windows, where there are constant, instantaenous updates on network connectivity. If it can be done in Windows I think it could be done in Linux:)
Offline
Well first, you need to define what you consider "internet access"? Then you can start thinking about how to monitor that.
Under which circumstances are you "connected"?
- Anytime the NIC has a link to a switch/modem/other and is "up"
- Anytime you can reach something in your ISP's network? (What if they have routing issues and you can't get anywhere else?)
- Anytime you can reach a specific local website? (What if that website goes down?)
- Anytime you can reach a specific overseas website? (What is there are international routing problems, but you still have national routing?)
The best compromise to determine "online" state is to ping my ISP's DNS server which is an ANYCAST address.
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
I use this - it's simple, but does exactly what I need...
$(host google.com>/dev/null && echo $GRN"ON" || echo $RED"NO")
Offline
I think NetworkManager (& associated GUI tools) does what you want, it gives you features quite similar to the little systray network thingie you find in Windows. I use it in KDE and it gives me no problems. Wiki link. I can't tell if you're just interested in writing something like this for educational purposes though, if that's the case then maybe this article will help you.
Offline
@Bralkein: Yeah, I sorta wanted to write a lightweight version of that/learn about this stuff. Thanks for the link, but unfortunately it only tells me the structure of a daemon, not the hardware/software interface I was looking for, or the information about sleeping. Thank you though.
@jasonwryan: I have one of those too, but I have to run it manually, it doesn't automatically run on a connect/disconnect/other network event.
@fukawi2: I agree with your qualification for 'online', now I just need an efficient way to check that state.
Thanks to everyone for their answers.
Last edited by RedScare (2010-12-31 15:26:23)
Offline
RedScare: Why not look at the source code for NetworkManager?
Offline