Documentation
¶
Overview ¶
Package ports answers "is anything listening on this port, and who is it".
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoOwner = errors.New("the other end of the connection was not found")
ErrNoOwner means the client end of a connection was not found, as for a connection from a process of another account that lsof cannot see.
var ErrUnsupported = errors.New("connection owners cannot be looked up on this platform")
ErrUnsupported means this platform cannot tell who holds a connection.
Functions ¶
func IPv6Loopback ¶
func IPv6Loopback() bool
IPv6Loopback reports whether the system has IPv6 loopback.
Types ¶
type ConnOwner ¶
type ConnOwner struct {
UID int
// Self is true when the client end belongs to this process too, as for
// a connection the daemon opened to itself.
Self bool
}
ConnOwner is who holds the client end of a TCP connection to this process.
type Exposure ¶ added in v0.4.0
type Exposure string
Exposure says from where a listener can be reached, judged by the addresses it listens on.
const ( // Loopback listeners answer only on this computer. Loopback Exposure = "loopback" // Tailnet listeners answer only on this machine's own Tailscale // addresses. Tailnet Exposure = "tailnet" // Network listeners answer on all interfaces or on another address, // such as one of the local network. Network Exposure = "network" )
func Classify ¶ added in v0.4.0
func Classify(addrs []string, own TailnetAddrs) Exposure
Classify returns the widest exposure of listening addresses as lsof or ss write them ("127.0.0.1", "[::1]", "*", "0.0.0.0", "[fe80::1%lo0]"), or "" for none. own gives this machine's Tailscale addresses; any other address, also one in Tailscale's ranges, and one it cannot parse count as reachable from the network.
type Listener ¶
type Listener struct {
Port int `json:"port"`
PID int `json:"pid"`
Command string `json:"command"`
Cwd string `json:"cwd,omitempty"`
// Addresses are the local addresses the process listens on at Port, as
// lsof or ss write them ("127.0.0.1", "[::1]", "*"), in the order found.
Addresses []string `json:"addresses,omitempty"`
}
Listener is a process listening on a TCP port.
func List ¶
List returns all TCP listeners visible to the current user, one entry per (port, pid) with all of its addresses, sorted by port, with working directories. It uses lsof and falls back to ss on Linux.
type TailnetAddrs ¶ added in v0.4.2
TailnetAddrs returns this machine's own Tailscale addresses, or none when Tailscale is unavailable. Classify calls it only for an address in Tailscale's ranges; a nil TailnetAddrs knows no addresses.
func (TailnetAddrs) Resolved ¶ added in v0.4.2
func (own TailnetAddrs) Resolved(lists ...[]string) TailnetAddrs
Resolved calls own at most once, when an address of the lists is in Tailscale's ranges, and returns a TailnetAddrs that answers that result, so a caller can classify under a lock without waiting for Tailscale.