ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
good day to all of you,
Im trying to do a C program that gets information from another program (TCPDUMP) and what i`m trying to do is run tcpdump from the terminal and get the information that I need from the output of tcpdump, and use it in my C program. My question is:
In a C program I can run a command from the shell, and use the output of that command in the C program?
Or in a Shell script I can call a C program? and pass the output of some functions in the script to the C program?
If there is a another way to do what I explained above,tell me, please.
Thanks for your time.
You could pipe the output of tcpdump into your C program, and then have the C program read stdin.
You could also have tcpdump capture to a file (see -w) and then just read the file back with your C program.
You could also just use libpcap directly in your C program to monitor the stream directly, but without more info on your purpose, that's probably "reinventing the wheel" ...
You could pipe the output of tcpdump into your C program, and then have the C program read stdin.
You could also have tcpdump capture to a file (see -w) and then just read the file back with your C program.
you could also do both. having your c program read from stdin is extremely handy for using it in a pipe line. you could have your c program read from stdin if there are no command line arguments, and otherwise use the filename passed to it throught the command line as input.
thanks for the advice.
If i decide to read the file, saved with the option -w of tcpdump, in the C program, how can read and save only some fields of the file, for expample grab only the src/dst port and the bytes sent?
because i only need these fields to work with them.
In a C program I can run a command from the shell, and use the output of that command in the C program?
I'd use popen().
Quote:
If i decide to read the file, saved with the option -w of tcpdump, in the C program, how can read and save only some fields of the file, for expample grab only the src/dst port and the bytes sent?
because i only need these fields to work with them.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.