Documentation ¶
Overview ¶
Package lib127 provides methods for mapping hostnames to random loopback addresses.
Index ¶
Constants ¶
const DefaultHostsFile = "/etc/hosts"
DefaultHostsFile is the default hosts file location.
Variables ¶
var ( // ErrHostnameInvalid indicates an invalid hostname. ErrHostnameInvalid = hosts.ErrHostnameInvalid // ErrHostnameIsIP indicates that an IP address was given as hostname. ErrHostnameIsIP = hosts.ErrHostnameIsIP // ErrCannotUnmapLocalhost indicates a request to unmap localhost. ErrCannotUnmapLocalhost = errors.New("127: cannot unmap localhost") )
These errors can be tested against using errors.Is. They are never returned directly.
Functions ¶
This section is empty.
Types ¶
type Hosts ¶
type Hosts struct {
// contains filtered or unexported fields
}
Hosts provide methods for mapping hostnames to random IP addresses. Its zero value is usable and operates on the default hosts file.
func Open ¶ added in v0.5.0
NewHosts opens a new Hosts using the given file. If filename is "" the default hosts file is opened.
Returned file system errors wrap *fs.PathError.
func (*Hosts) IP ¶ added in v0.5.0
IP returns the IP address associated with the specified hostname. Returns an empty string if hostname were not found.
Returned hostname errors can be matched against ErrInvalidHostname and ErrHostnameIsIP.
func (*Hosts) Map ¶ added in v0.5.0
Map maps the specified hostname to a random unnasigned loopback address, and returns that IP. If the hostname is already mapped, we return the already assigned IP address instead.
Returned hostname errors can be matched against ErrInvalidHostname and ErrHostnameIsIP.