External comands in C?


 
Thread Tools Search this Thread
Top Forums Programming External comands in C?
# 1  
Old 01-06-2003
External comands in C?

Hey all,

I'm writting my first C program (Apart from the little ones I did to learn the program).

What I want for this program to do is ping a range of IP's and then place the reply if alive into a file the compare all in that file to the /etc/hosts file to find the host name.

I know I could do it all ina script BUT I want to learn C and do it in that.

The reason I want it to do this is so I can check the main computers on the network can see all the other computers and also to check up if anyone has added any computers onto the network.

I'm pretty sure I can do most of this programming. But how do I call apon a external command? Like I'll need to use 'ping' and compare or something the same.

Also another quickie.

Once I have found the IP 64.1.128.15 (example only) in the 'etc/hosts' file how can I take the WHOLE line and place that into the last file for viewing all this data.

Thanks in advanced for the help.
merlin
# 2  
Old 01-07-2003
I presume that you may have to work with the following Networking Services Library Functions like:
sethostent ( ) , gethostent ( ) and endhostent ( ) and some Sockets Library Functions like:
ntohs ( ) and inet_ntoa ( ) and
Standard C Library Functions like:
system ( )
There can be multiple ways to solve your requirement and much depends upon how you want to implement it.
See man pages for more explanations.

Last edited by S.P.Prasad; 01-07-2003 at 06:33 AM..
# 3  
Old 01-08-2003
USe System

If you want to execute a Unix command like Ping from a C programe them use the "system" function and execute it.

Check the manual.

man system
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use of the below ftp comands

plz let me know what the below ftp is doing it . ftp -m amazon-d . -i /test/load/y748_W*.stc (1 Reply)
Discussion started by: ramkumar15
1 Replies

2. UNIX for Dummies Questions & Answers

Execute multiple comands on one single line

hi, I have a litle problem i wish to excute this comand : ./test.sh -e txt /home -l a so what it says is that "-e" shows me all the extenions that are ".txt" in "home" this works but then i wish that "-l" will show all files begining in this case with the letter "a" . Both comands work... (5 Replies)
Discussion started by: samirboss
5 Replies

3. UNIX for Dummies Questions & Answers

External HDD

I need to get an external HDD for a SUN server running Solaris 10. The Western Digital that I have will not recognize and when I went looking for drivers WD only has them for MAC and Windows. Is there a External HDD that is known to work with Unix? (24 Replies)
Discussion started by: SIFT3R
24 Replies

4. Shell Programming and Scripting

Script Help - Multi Comands

Hi guys I am trying to get a bunch of lines into a .sh script that will let me easily run a bunch of commands on its own without me having to be there... I have done this with other things but apparetnly it doesn't like to use yum.. I will post my script you will see what im trying to do.. ... (3 Replies)
Discussion started by: Bigstack
3 Replies

5. Linux

External disk

Hi, I connected a external hard disk to my linux machine(Redhat 5) and shared the external hard disk by using NFS. The problem is hard disk becoming read-only file system after some time, could some one please tell me the reason for it. I created two partitions with ext3 filesystem in... (10 Replies)
Discussion started by: ktrimu
10 Replies

6. Solaris

Solaris 10 network, process, database related comands

Hi everbody, Can anyone let me know the resources for list of network, process, database related commands of solaris10 possibly with little bit of explanation. Thanks in advance, Chandra Sekhar. (1 Reply)
Discussion started by: chandoo.java
1 Replies

7. Cybersecurity

comands inside the script

hi, i want to put a set of commands inside a script and executing commands sequentially. there are 2 commands, the first command copies the program from my machine to another machine, execute it and get the result on my machine. the second command removes the program which was copied to the... (4 Replies)
Discussion started by: mercuryshipzz
4 Replies

8. UNIX for Advanced & Expert Users

For Loops Within Ftp Comands

I am having trouble getting files to ftp over when I run the file names through a loop. If I just do one file it works, but inside of a for loop it does not. Help! ################section 2 cd /home/salazar/chk_data chmod 777 * ftp -n 161.241.--.-- <<! user anonymous \n ascii for... (6 Replies)
Discussion started by: jsalz638
6 Replies

9. Shell Programming and Scripting

how to identify the type of shell using comands..

Dear friends, please tell me how to identify the type of the shell (whether cShell, kshell or anything else) please tell me the command. waiting for ur reply.... regards, swamymns (2 Replies)
Discussion started by: swamymns
2 Replies

10. Solaris

External USB

Is it possible to install Solaris 10 on an external USB drive? I'd like to dual boot Linux and Solaris 10. Thanks! (2 Replies)
Discussion started by: otterit
2 Replies
Login or Register to Ask a Question