views:

433

answers:

2

So I'm running PPP under linux with a cellular modem. The program I'm writing needs to know if the link is active before sending any data.

What are my options to check

  • if the link is available
  • if it routes to a server I control (it doesn't go to the internet as I said earlier)

Also, what is the best way to restart it - I'd like to have program control over when it starts and stops, so I assume an init.d isn't appropriate. Using system() doesn't seem to give a PID, are there other options besides fork() and the gaggle of exec??() calls?

C on Linux on ARM (custom distribution using buildroot). Yes, even though I've got my hands inside the kernel I'm still a newbie, so please be verbose or give pointers where possible to more in-depth info.

+1  A: 

You could parse /proc/net/route.

Ted Percival
+2  A: 

You can use the ip-up script functionality of pppd to have it execute a program when the IP interface is up and ready. Details are in the pppd(8) man page - search for "ip-up".

To restart pppd, use the "linkname" parameter to set a known pifdile name (/var/run/ppp-name.pid). Also use the persist option. When you want to restart pppd, send the SIGHUP signal. Again, this is described in the man page.

camh