05-31-06 06:18 PM
guilherme.oliveira@gmail.com wrote:
> Hi again.
>
> I'm trying to do something with netstat but it's giving segmentation
> fault (core dumped):
>
>
> #include <stdio.h>
> #include <unistd.h>
>
> void recv()
> {
> #define LINE_LENGTH 500
> char output_recv[LINE_LENGTH];
> FILE *grab_recv;
>
> /* exec netstat -s */
>
> execl("/usr/bin/netstat -s -p tcp", "", grab_recv);
You are confusing popen/system/exec**
> /* grab the result */
Your program does not exist any more.
Unless execl() failed.
In that case grab_recv will be uninitialised.
Either way you lose.
> fgets(output_recv, LINE_LENGTH, grab_recv);
> pclose(grab_recv);
>
> /* print the result */
>
> sprintf (output_recv, "Recebidos %s bytes ", output_recv);
> puts(output_recv);
> }
>
> main ()
> {
> /* exec recv() to know received traffic */
>
> recv();
recv() conflicts with a systemcall/library function.
Choose another name.
[vbcol=seagreen]
> }
>
> /* EOF */
>
>
> guilherme.oliveira@gmail.com escreveu:
>
Don't toppost. Even when you are replying to yourself :-)
HTH,
AvK
[ Post a follow-up to this message ]
|