package netlink import ( "encoding/binary" "errors" "fmt" "net" "syscall" "github.com/evilsocket/opensnitch/daemon/log" "github.com/vishvananda/netlink/nl" ) // This is a modification of https://github.com/vishvananda/netlink socket_linux.go - Apache2.0 license // which adds support for query UDP, UDPLITE and IPv6 sockets to SocketGet() const ( SOCK_DESTROY = 21 sizeofSocketID = 0x30 sizeofSocketRequest = sizeofSocketID + 0x8 sizeofSocket = sizeofSocketID + 0x18 ) // https://elixir.bootlin.com/linux/latest/source/include/net/tcp_states.h const ( TCP_INVALID = iota TCP_ESTABLISHED TCP_SYN_SENT TCP_SYN_RECV TCP_FIN_WAIT1 TCP_FIN_WAIT2 TCP_TIME_WAIT TCP_CLOSE TCP_CLOSE_WAIT TCP_LAST_ACK TCP_LISTEN TCP_CLOSING TCP_NEW_SYN_RECV TCP_MAX_STATES ) var ( native = nl.NativeEndian() networkOrder = binary.BigEndian TCP_ALL = uint32(1< %v:%d - %d:%v -> %v:%d", n, TCPStatesMap[s.State], srcPort, local, remote, dstPort, s.ID.SourcePort, s.ID.Source, s.ID.Destination, s.ID.DestinationPort) continue } // INode can be zero for some connections states, like TCP_FIN_WAT, TCP_TIME_WAIT, etc. // so don't exclude those entries, in order to get all sockets. sock[n] = s } return sock, err }