Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking network status and controlling PPP in a program

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

like image 935
Adam Davis Avatar asked Nov 18 '25 22:11

Adam Davis


2 Answers

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

like image 138
camh Avatar answered Nov 20 '25 14:11

camh


You could parse /proc/net/route.

like image 28
Ted Percival Avatar answered Nov 20 '25 16:11

Ted Percival



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!