netstat.go 771 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package netstat returns the local machine's network connection table.
  4. package netstat
  5. import (
  6. "errors"
  7. "net/netip"
  8. "runtime"
  9. )
  10. var ErrNotImplemented = errors.New("not implemented for GOOS=" + runtime.GOOS)
  11. type Entry struct {
  12. Local, Remote netip.AddrPort
  13. Pid int
  14. State string // TODO: type?
  15. OSMetadata OSMetadata
  16. }
  17. // Table contains local machine's TCP connection entries.
  18. //
  19. // Currently only TCP (IPv4 and IPv6) are included.
  20. type Table struct {
  21. Entries []Entry
  22. }
  23. // Get returns the connection table.
  24. //
  25. // It returns ErrNotImplemented if the table is not available for the
  26. // current operating system.
  27. func Get() (*Table, error) {
  28. return get()
  29. }