tags:

views:

114

answers:

3

Hi All,

I need to send the arp of a IP to get it's mac address which is configured on different machine. I am arping this ip from a C program by "system(arping -c 3 -i eth0 ) but I see that this is hanged in there.

But if I run the same command from bash "arping -c 3 -i eth0 " it get executed successfully.

I could not understand why system command hanged in this case while the command is successfully completed when run from bash.

Thanks,

A: 

try system("arping -c 3 -I eth0 ip-addr"); something like:

main() { system("arping -c 3 -I eth0 192.168.10.1"); }

rohitude
A: 

Are you using any child process to execute above ?

From Definition of system() : The system() function shall ignore the SIGINT and SIGQUIT signals, and shall block the SIGCHLD signal, while waiting for the command to terminate. The system() function shall not return until the child process has terminated.

Recommendations:

1.check on the return value of system() & take appropriate decision.

Eg: If return value is zero it means command processor is not available.If a child process cannot be created, or if the termination status for the command language interpreter cannot be obtained, system() shall return -1 and set errno to indicate the error.

2.Use complete shell commands to be executed.

Eg: system("arping -c 3 -I eth0 10.203.198.10");

Kedar
I have taken both the conditions in consideration. when I execute system(NULL) it return with none zero so command processor is available.And I am using the complete shell command in my program.
neeraj
+1  A: 

Since you said it was hanging you can try:

strace -o my_prog.strace -f ./my_prog

and then kill it after it hangs. Then you can view the strace output file my_prog.strace and try to figure out what went wrong.

You may want to look at the strace man page to see other options that you might like use -- of particular use to me are ones that make it show more data in buffer (and string) input/output.

If it's not really hanging you should check the return value from your call to system( ) and then inspect errno.

edit

Something that I just thought of that could cause a hang would be if arping was actually a link to a setuid root program that did sudo on the real arping and it is waiting on a password to be typed in, but the terminal for that program isn't set correctly.

nategoose