Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-20-2004, 09:34 AM   #1
Registered: Oct 2003
Location: Bucharest
Distribution: Debian Sarge, Slackware Current, Ubuntu
Posts: 183

Rep: Reputation: 30
using ping and ifconfig in C program

Can I use commands like ping and ifconfig in a C file ? if so, how ?
Old 12-20-2004, 09:39 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
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).
Old 12-20-2004, 09:52 AM   #3
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95

Rep: Reputation: 15
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Ping Issue - Can't ping localhost but can ping others on LAN code_slinger Linux - Networking 15 03-30-2015 03:39 PM
connecting /sbin/ifconfig to bash command ifconfig flammable2 Fedora 4 11-12-2005 08:58 AM
ping program not installed in redhat linux 7.1 domeili Linux - Newbie 1 08-02-2004 10:38 AM
how to log for a program such as "ping" ?? wohaolouis Linux - Security 1 02-03-2004 03:46 PM
Need program to Ping ISP in Mnk 9.1 esage Mandriva 4 10-29-2003 12:59 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration