using ping and ifconfig in C program
Can I use commands like ping and ifconfig in a C file ? if so, how ?
|
You can spawn an external command using the system() command.
Code:
system("ping 127.0.0.1 -n 10"); 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). |
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 03:05 AM. |