Index | Files

package netutil

import ""

Package netutil identifies the system userid responsible for localhost TCP connections.

Package netutil identifies the system userid responsible for localhost TCP connections.


Package Files

ident.go ident_cgo.go netutil.go


var (
    ErrNotFound      = errors.New("netutil: connection not found")
    ErrUnsupportedOS = errors.New("netutil: not implemented on this operating system")

func AddrPairUserid Uses

func AddrPairUserid(local, remote net.Addr) (uid int, err error)

AddrPairUserid returns the local userid who owns the TCP connection given by the local and remote ip:port (lipport and ripport, respectively). Returns ErrNotFound for the error if the TCP connection isn't found.

func AwaitReachable Uses

func AwaitReachable(addr string, maxWait time.Duration) error

AwaitReachable tries to make a TCP connection to addr regularly. It returns an error if it's unable to make a connection before maxWait.

func ConnUserid Uses

func ConnUserid(conn net.Conn) (uid int, err error)

ConnUserid returns the uid that owns the given localhost connection. The returned error is ErrNotFound if the connection wasn't found.

func HasPort Uses

func HasPort(s string) bool

HasPort, given a string of the form "host", "host:port", or "[ipv6::address]:port", returns true if the string includes a port.

func HostPort Uses

func HostPort(urlStr string) (string, error)

HostPort takes a urlStr string URL, and returns a host:port string suitable to passing to net.Dial, with the port set as the scheme's default port if absent.

func HostPortToIP Uses

func HostPortToIP(hostport string, ctx *net.TCPAddr) (hostaddr *net.TCPAddr, err error)

HostPortToIP parses a host:port to a TCPAddr without resolving names. If given a context IP, it will resolve localhost to match the context's IP family.

func IsFQDN Uses

func IsFQDN(domain string) bool

IsFQDN reports whether domain looks like a fully qualified domain name.

func ListenHostPort Uses

func ListenHostPort(listenAddr string) (string, error)

ListenHostPort maps a listen address into a host:port string. If the host part in listenAddr is empty or, localhost is used instead.

func ListenOnLocalRandomPort Uses

func ListenOnLocalRandomPort() (net.Listener, error)

ListenOnLocalRandomPort returns a TCP listener on a random localhost port.

func Localhost Uses

func Localhost() (net.IP, error)

Localhost returns the first address found when doing a lookup of "localhost". If not successful, it looks for an ip on the loopback interfaces.

func RandPort Uses

func RandPort() (int, error)

RandPort returns a random port to listen on.

Package netutil imports 16 packages (graph) and is imported by 132 packages. Updated 2018-01-31. Refresh now. Tools for package owners.