LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-20-2004, 08:34 AM   #1
Menestrel
Member
 
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, 08:39 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
You can spawn an external command using the system() command.
Code:
system("ping 127.0.0.1 -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, 08:52 AM   #3
hk_linux
Member
 
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.
 
  


Reply


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 13 03-17-2011 02:47 AM
connecting /sbin/ifconfig to bash command ifconfig flammable2 Fedora 4 11-12-2005 07:58 AM
ping program not installed in redhat linux 7.1 domeili Linux - Newbie 1 08-02-2004 09:38 AM
how to log for a program such as "ping" ?? wohaolouis Linux - Security 1 02-03-2004 02:46 PM
Need program to Ping ISP in Mnk 9.1 esage Mandriva 4 10-29-2003 11:59 AM


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

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