How to get a list of open sockets in Linux using C?

前端 未结 4 1643
名媛妹妹
名媛妹妹 2020-12-15 11:39

Is there a way to get a list of all open sockets ( socket address or socket descriptor ) in Linux using C in user-space or kernel?

Thank you

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 12:35

    Open and read the following:

    /proc/net/tcp - a list of open TCP sockets

    /proc/net/udp - a list of open UDP sockets

    /proc/net/raw - a list all the "raw" sockets

    These are like "regular" files that you open and read with a filehandle and will give you all the information you could possibly need about each socket.

提交回复
热议问题