-   Programming (
-   -   using ping and ifconfig in C program (

Menestrel 12-20-2004 08:34 AM

using ping and ifconfig in C program
Can I use commands like ping and ifconfig in a C file ? if so, how ?

rjlee 12-20-2004 08:39 AM

You can spawn an external command using the system() command.

system("ping -n 10");
This will return immediately; use an ampusand (&) on the command-line if that's not what you want.

If you want to capture the output, then you will need to look into using popen(), and read the command's output like a file (or any other stream).

hk_linux 12-20-2004 08:52 AM

Using system call from a C code blocks the interupts. See man system.

For ping, create a raw socket with ICMP protocol.
For ifconfig, create DGRAM socket and use ioctl (SIOCGIFCONF), u can find the interfaces in the system.

Some time back, i downloaded the code from the net. I dont remember the site. May be u can google and find it out.

All times are GMT -5. The time now is 11:18 AM.