netutil

package
v0.0.0-...-d6cb8d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2015 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

Functions

func AddrPairUserid

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

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

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 HostPort

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

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 ListenOnLocalRandomPort

func ListenOnLocalRandomPort() (net.Listener, error)

ListenOnLocalRandomPort returns a TCP listener on a random localhost port.

func Localhost

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL