Results 1 to 9 of 9
Hi!
I need to create a C/C++ program in Linux that succeeds in detecting how many tcp-sockets and what tcp-sockets are created by the other processes in the system in ...
- 07-25-2010 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 8
[C/C++] Program detecting new sockets
Hi!

I need to create a C/C++ program in Linux that succeeds in detecting how many tcp-sockets and what tcp-sockets are created by the other processes in the system in a particular time interval (e.g., the interval time this application is running in). Then, I'd need to get some information like local/remote port number and local/remote ip address of each of these sockets.
Do you have any suggestion? I've been looking for something for several days, but I haven't found anything yet.
- 07-26-2010 #2Just Joined!
- Join Date
- Feb 2006
- Posts
- 13
Netstat command might be helpful for you. Redirect the output to a text file and you can parse it.
- 07-26-2010 #3Just Joined!
- Join Date
- Sep 2009
- Posts
- 8
No. Unfortunately, it's not helpful for me, because I'm looking for something that "succeeds in detecting how many tcp-sockets and what tcp-sockets are created by the other processes in the system in a particular time interval". Netstat shows me which sockets are active in the instant I use this command.
- 07-27-2010 #4Just Joined!
- Join Date
- Feb 2006
- Posts
- 13
When I said netstat. I want you to explore the netstat options.
netstat -a give out all the sockets as well as the type of the socket.
As for as connected socket over a period of time, either you have write your own application to calculate it or you can look for some open source application.
- 07-27-2010 #5Just Joined!
- Join Date
- Sep 2009
- Posts
- 8
- 07-29-2010 #6Just Joined!
- Join Date
- Oct 2009
- Posts
- 85
- 07-29-2010 #7Just Joined!
- Join Date
- Sep 2009
- Posts
- 8
- 07-29-2010 #8Just Joined!
- Join Date
- Oct 2009
- Posts
- 85
Or you can use cat /proc/net/tcp where you can get the remote ip : port and local ip
ort number.
Have a look at this page :
Exploring the <tt>/proc/net/</tt> Directory - O'Reilly Media
Here he tells that
The local IP address and port number for the socket. The IP address is displayed as a little-endian four-byte hexadecimal number; that is, the least significant byte is listed first, so you'll need to reverse the order of the bytes to convert it to an IP address. The port number is a simple two-byte hexadecimal number.
- 07-29-2010 #9Just Joined!
- Join Date
- Oct 2009
- Posts
- 85
Actually socklist is a perlscript.. Im sure that you download online.


Reply With Quote
