Question

I'm calling system command

system("tftp -m binary 192.168.1.1 -c get myfile  > /dev/null") ;

it works fine when tftp server is running but it makes my c program crashed when tftp server is off.

Is there a way to check whether the server is available or not in c source code ?

Was it helpful?

Solution

I think your problem lies not in the availability of the server, but the fact that tftp (at least on my Ubuntu box) does not support the command-line arguments you've provided. As a matter of fact, the only command-line argument that it does support is the name of the server.

However, you could try piping commands into tftp (simulating an interactive session), like so:

system( "echo -e \"binary\\nget myfile\\nquit\" | tftp 192.168.1.1" );

If the server isn't available, it'll time out after a few seconds and return control to your program.

OTHER TIPS

system("echo -e \"timeout 1\\nget myfile\" | tftp 192.168.1.1");

I used timeout options instead of quit command because actual latency which makes my program watchdog reset is performing on get command execution. So quit can not prevent this.

On the otherhand I decided to call tftp command on a bash script starting my c program.

I think that calling tftp commad on a real time c program is faulty.

Many thanks Ethan .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top