traffic counter in C
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > traffic counter in C




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    traffic counter in C  
guilherme.oliveira@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-06 12:18 PM

Hi !

I want to do a traffic counter in C for FreeBSD.
I have already done the daemon with forks but don't know where to get
the value of transfered data becayse these value isn't in '/proc'
(empty) or 'sysctl -a'

Any ideas ?






[ Post a follow-up to this message ]



    Re: traffic counter in C  
guilherme.oliveira@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-06 06:18 PM


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);

/* grab the result */

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();

}

/* EOF */


guilherme.oliveira@gmail.com escreveu:
> Hi !
>
> I want to do a traffic counter in C for FreeBSD.
> I have already done the daemon with forks but don't know where to get
> the value of transfered data becayse these value isn't in '/proc'
> (empty) or 'sysctl -a'
>
> Any ideas ?






[ Post a follow-up to this message ]



    Re: traffic counter in C  
moi


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: traffic counter in C  
ed


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-31-06 06:18 PM

On 31 May 2006 02:42:09 -0700
guilherme.oliveira@gmail.com wrote:

> I want to do a traffic counter in C for FreeBSD.
> I have already done the daemon with forks but don't know where to get
> the value of transfered data becayse these value isn't in '/proc'
> (empty) or 'sysctl -a'

getifdata is your friend

--
Regards, Ed                      :: http://www.keyra.co.uk
proud bash hacker
:%s/Open Source/Free Software/g  :: Free DNS available






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:13 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register