Networking Forums  

Go Back   Networking Forums > Networking Newsgroups > Linux Networking

socket programming

Reply
 
Thread Tools Display Modes
  #1  
Old 02-12-2008, 07:09 PM
Default socket programming



hello ... this is rakesh ..... i am new to socket programming ..... i
just want to know wheather if we could get statistics related to a
particular port using socket programming in C? statistics in the
sense .... no of packets transmitted,received etc ..... or is there
any file in linux( i use fedora) which gives this kind of
information? .... thanks in advance !!!


rak.dontmess@gmail.com
Reply With Quote
  #2  
Old 02-12-2008, 07:53 PM
Lew Pitcher
Guest
 
Posts: n/a
Default Re: socket programming

On Feb 12, 2:09 pm, rak.dontm...@gmail.com wrote:
> hello ... this is rakesh ..... i am new to socket programming ..... i
> just want to know wheather if we could get statistics related to a
> particular port using socket programming in C? statistics in the
> sense .... no of packets transmitted,received etc ..... or is there
> any file in linux( i use fedora) which gives this kind of
> information? .... thanks in advance !!!


Why not use the "/sbin/ifconfig" file? As in...

struct FILE *Stats = popen("/sbin/ifconfig eth0","r");

if (Stats)
{
char buff[256];

while (fgets(buff, sizeof(buff), Stats) != EOF)
fputs(buff,stdout);
pclose(Stats);
}
Reply With Quote
  #3  
Old 02-12-2008, 10:13 PM
Rick Jones
Guest
 
Posts: n/a
Default Re: socket programming

(E-Mail Removed) wrote:
> hello ... this is rakesh ..... i am new to socket programming
> ..... i just want to know wheather if we could get statistics
> related to a particular port using socket programming in C?
> statistics in the sense .... no of packets transmitted,received etc
> ..... or is there any file in linux( i use fedora) which gives this
> kind of information? .... thanks in advance !!!


The closest you can get IIRC is what is reported by a TCP_INFO
getsockopt(), which is described in the manpage for tcp under linux.
It is decidedly non-portable. That of course won't do anything for
UDP, or DCCP or SCTP etc etc. And it is very specific to the Linux
stack - it may not be there on other stacks.

There might be some way using netfilter (?) to gather those stats, but
I'm not sufficiently familiar with how one uses that to say.

rick jones
--
portable adj, code that compiles under more than one compiler
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
Reply With Quote
  #4  
Old 02-12-2008, 10:14 PM
Rick Jones
Guest
 
Posts: n/a
Default Re: socket programming

Lew Pitcher <(E-Mail Removed)> wrote:
> On Feb 12, 2:09 pm, rak.dontm...@gmail.com wrote:
> > hello ... this is rakesh ..... i am new to socket programming ..... i
> > just want to know wheather if we could get statistics related to a
> > particular port using socket programming in C? statistics in the
> > sense .... no of packets transmitted,received etc ..... or is there
> > any file in linux( i use fedora) which gives this kind of
> > information? .... thanks in advance !!!


> Why not use the "/sbin/ifconfig" file? As in...


> struct FILE *Stats = popen("/sbin/ifconfig eth0","r");


> if (Stats)
> {
> char buff[256];


> while (fgets(buff, sizeof(buff), Stats) != EOF)
> fputs(buff,stdout);
> pclose(Stats);
> }


That would give the count of everything that went through the
interface, not just that for the OP's port of interest. Now, if he
"knew" that his was the only active sockets application using that
interface it would give him what he wants, but I doubt that will ever
be the case.

rick jones
--
web2.0 n, the dot.com reunion tour...
these opinions are mine, all mine; HP might not want them anyway...
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
Reply With Quote
  #5  
Old 02-13-2008, 12:00 AM
David Schwartz
Guest
 
Posts: n/a
Default Re: socket programming

On Feb 12, 11:09 am, rak.dontm...@gmail.com wrote:
> hello ... this is rakesh ..... i am new to socket programming ..... i
> just want to know wheather if we could get statistics related to a
> particular port using socket programming in C? statistics in the
> sense .... no of packets transmitted,received etc ..... or is there
> any file in linux( i use fedora) which gives this kind of
> information? .... thanks in advance !!!


This is one thing I really like about FreeBSD and really miss about
Linux. FreeBSD has some great ways to track flows passing through it
and track traffic by destination and by port.

I know of no good ways to do this on Linux. I would be very interested
in possible ways to do this because I have been forced to use FreeBSD
for several firewalls where I would prefer Linux because I can't get
good statistics on traffic by destination host and/or by flow.

HTB also can't easily regulate traffic by host unless you reserve
bandwidth for every single host. That's awkward when you have tens of
thousands of hosts.

DS
Reply With Quote
Reply

Tags
programming, socket

Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump


All times are GMT. The time now is 02:31 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.