Click to See Complete Forum and Search --> : I m just starting with C
groundzero
05-04-2001, 01:18 PM
I have a question. Im my code how do i tell linux to :
ping hostname and as long is it gets a responce print blablabla>>>
Thanx'
also how can issue a reboot command from user level and not root. Its ok if the are promted for the su password.
I don't have a direct answer for you; but this page will help you with C sockets.
http://www.ecst.csuchico.edu/~beej/guide/net/
jemfinch
05-04-2001, 03:15 PM
Really, you should pick a better language to learn, like Python.
To allow a user to reboot, put this in a file and give it execute permissions:
#!/bin/sh
su -c 'shutdown -r now'
Jeremy
pinoy
05-04-2001, 06:17 PM
ping involves using a raw socket, so you can format your own icmp packet, and you can also read icmp replies. Not terribly hard, but if you're just starting with C, it may be a while before you get comfortable with it.
satchel
05-07-2001, 12:01 PM
You can do a "ping -c 1 $addr"
Then check for the returncode. If its
0(success/host is up) println "blahh"
if its 1(failure/non zero) then do something else. I'm partial to ksh or Perl for this stuff. Something like this in C......?
rc=0
system("ping -c 1 $addr");
if rc
then println "blahhhh"
else
exit
I'm sure this syntax isn't right but this is the basic idea.