LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2012, 09:45 AM   #1
turkejd
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Rep: Reputation: Disabled
Socket throughput in C


Hi everybody,

I am writing a simple program in C that compares the performances of various sockets bound to different interfaces and then decide what is the best interface to use in a certain moment, for a certain destination address. This application (let's call it A) will execute while another application (B) is using these sockets (e.g. for streaming).

I thought that the throughput might be the best indicator of performance, but I can't find a method to get the throughput of a socket (which is receiving data, and not sending) in C.

Also, this application can directly take information from the kernel using a /proc file, so I can use all informations inside struct sock and struct tcp_sock.

The important thing is that I cannot send packets in order to calculate this, but only use the already ongoing traffic.

Can someone help me?

Thanks
 
Old 02-01-2012, 10:09 AM   #2
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
Socket Monitor

I am a little unclear on your goal but if you wish to monitor all of the sockets the netstat utility is useful for viewing your open socket connections.

netstat -a to see all connections

You will notice a very large amount of data concerning the sockets activity and a little read using man netstat would be most effective. So you don't actually have to write any code to see this as it has already been done for you.
 
Old 02-01-2012, 11:55 PM   #3
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
An afterthought

I reread your post and there is a way to just use C to get the same information as netstat.

FILE *fp; /* FILE stream for popen */
char *cmdstring = "netstat -a";
char buf[BUFSZ]; /* Buffer for input */
/*
Create the pipe
*/
if((fp = popen(cmdstring, "r")) == NULL) err_quit("popen");
/*
Read cmdstring's output
*/
while((fgets(buf,BUFSZ, fp)) != NULL)
printf("%s", buf);
/*
Close and reap the exit status
*/
pclose(fp);
exit(EXIT_SUCCESS);

stolen quite handily from Kurt Wall
 
Old 02-02-2012, 01:28 AM   #4
turkejd
LQ Newbie
 
Registered: Jan 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
Hi,

thanks for the reply, but netstat doesn't provide informations on the throughput of the sockets.
I read the man and it seems that there is nothing like bit/s for every tcp socket.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
/usr/sbin/in.telnetd: getpeername: Socket operation on non-socket vnaveen Linux - Networking 1 05-05-2009 04:42 AM
Can't connect to UNIX socket /var/run/clamav/clamd.socket ganick Linux - Server 8 08-01-2008 01:22 PM
AF_LOCAL domain socket versus AF_INET socket performance zzaappp Linux - General 0 06-19-2008 07:50 AM
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 07:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration