Find the answer to your Linux question:
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    8

    Question [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.

  2. #2
    Just 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.

  3. #3
    Just Joined!
    Join Date
    Sep 2009
    Posts
    8

    Thumbs down

    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.

  4. #4
    Just 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.

  5. #5
    Just Joined!
    Join Date
    Sep 2009
    Posts
    8

    Smile

    Quote Originally Posted by srinathduraisamy View Post
    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.
    I already explored netstat options, but none of them help me.

    Quote Originally Posted by srinathduraisamy View Post
    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.
    It's not simple writing my own application to do that, for this reason I'm asking for help and suggestions here.

  6. #6
    Just Joined!
    Join Date
    Oct 2009
    Posts
    85
    Quote Originally Posted by thecell View Post
    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.
    I'm not sure but socklist can be helpful and read somewhere that sockstat is a command to get the list of open sockets.
    Try for the above 2 commands may be helpful

  7. #7
    Just Joined!
    Join Date
    Sep 2009
    Posts
    8
    Quote Originally Posted by maheshgupta024 View Post
    I'm not sure but socklist can be helpful and read somewhere that sockstat is a command to get the list of open sockets.
    Try for the above 2 commands may be helpful
    The man comand tells me these command don't exist. Looking for sockstat by Google, I found it's a FreeBSD command (I think it's similar to netstat, about which we speaked).

  8. #8
    Just 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 iport 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.

  9. #9
    Just Joined!
    Join Date
    Oct 2009
    Posts
    85
    Actually socklist is a perlscript.. Im sure that you download online.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •