net

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: BSD-3-Clause Imports: 9 Imported by: 8

Documentation

Overview

Package net provide constants and library for networking.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHostAddress = errors.New("invalid host address")
)

List of error messages.

Functions

func IsHostnameValid

func IsHostnameValid(hname []byte, isFQDN bool) bool

IsHostnameValid will return true if hostname is valid, otherwise it will return false. They must begin with alphanumeric character or "_" and end with an alphanumeric character. Host names may contain only alphanumeric characters, minus signs ("-"), underscore ("_"), and periods (".").

If isFQDN is true, the hostname must at least contains two labels; otherwise it will be invalid.

See rfc952 and rfc1123.

func IsIPv4 added in v0.7.0

func IsIPv4(ip net.IP) bool

IsIPv4 will return true if string representation of IP contains three dots, for example "127.0.0.1".

func IsIPv6 added in v0.7.0

func IsIPv6(ip net.IP) bool

IsIPv6 will return true if string representation of IP contains two or more colons ":", for example, "::1".

func IsTypeTCP

func IsTypeTCP(t Type) bool

IsTypeTCP will return true if t is type of TCP(4,6); otherwise it will return false.

func IsTypeTransport

func IsTypeTransport(t Type) bool

IsTypeTransport will return true if t is type of transport layer, i.e. tcp(4,6) or udp(4,6); otherwise it will return false.

func IsTypeUDP

func IsTypeUDP(t Type) bool

IsTypeUDP will return true if t is type of UDP(4,6); otherwise it will return false.

func ParseIPPort

func ParseIPPort(address string, defPort uint16) (host string, ip net.IP, port uint16)

ParseIPPort parse address into hostname/address, IP and port. If address is not an IP address, it will return the address as hostname (without port number if its exist) and nil on ip. In case of port is empty or invalid, it will set to defPort.

func ParseTCPAddr

func ParseTCPAddr(address string, defPort uint16) (udp *net.TCPAddr, err error)

ParseTCPAddr parse IP address into standard library TCP address. If address is not contains IP address, it will return nil with error. In case of port is empty, it will set to default port value in defPort.

func ParseUDPAddr

func ParseUDPAddr(address string, defPort uint16) (udp *net.UDPAddr, err error)

ParseUDPAddr parse IP address into standard library UDP address. If address is not contains IP address, it will return nil with error. In case of port is empty, it will set to default port value in defPort.

func ToDotIPv6 added in v0.7.0

func ToDotIPv6(ip net.IP) (out []byte)

ToDotIPv6 convert the IPv6 address format from "::1" format into "0.0.0.0 ... 0.0.0.1".

This function only useful for expanding SPF macro "i" or when generating query for DNS PTR.

Types

type Poll added in v0.10.1

type Poll interface {
	//
	// Close the poll.
	//
	Close()

	//
	// RegisterRead add the file descriptor to read poll.
	//
	RegisterRead(fd int) (err error)

	//
	// ReregisterRead register the file descriptor back to events.
	// This method must be used on Linux after calling WaitRead.
	//
	// See https://idea.popcount.org/2017-02-20-epoll-is-fundamentally-broken-12/
	//
	ReregisterRead(idx, fd int)

	//
	// UnregisterRead remove file descriptor from the poll.
	//
	UnregisterRead(fd int) (err error)

	//
	// WaitRead wait for read event received and return list of file
	// descriptor that are ready for reading.
	//
	WaitRead() (fds []int, err error)
}

Poll represent an interface to network polling.

func NewPoll added in v0.10.1

func NewPoll() (Poll, error)

NewPoll create and initialize new poll using epoll for Linux system or kqueue for BSD or Darwin (macOS).

type ResolvConf

type ResolvConf struct {
	// Local domain name.
	// Most queries for names within this domain can use short names
	// relative to the local domain.  If set to '.', the root domain
	// is considered.  If no domain entry is present, the domain is
	// determined from the local hostname returned by gethostname(2);
	// the domain part is taken to be everything after the first '.'.
	// Finally, if the hostname does not contain a domain part, the
	// root domain is assumed.
	Domain string

	// Search list for host-name lookup.
	// The search list is normally determined from the local domain
	// name; by default, it contains only the local domain name.
	// This may be changed by listing the desired domain search path
	// following the search keyword with spaces or tabs separating
	// the names.  Resolver queries having fewer than ndots dots
	// (default is 1) in them will be attempted using each component
	// of the search path in turn until a match is found.  For
	// environments with multiple subdomains please read options
	// ndots:n below to avoid man-in-the-middle attacks and
	// unnecessary traffic for the root-dns-servers.  Note that this
	// process may be slow and will generate a lot of network traffic
	// if the servers for the listed domains are not local, and that
	// queries will time out if no server is available for one of the
	// domains.
	//
	// The search list is currently limited to six domains with a
	// total of 256 characters.
	Search []string

	// Name server IP address
	// Internet address of a name server that the resolver should
	// query, either an IPv4 address (in dot notation), or an IPv6
	// address in colon (and possibly dot) notation as per RFC 2373.
	// Up to 3 name servers may be listed, one per keyword.  If there are
	// multiple servers, the resolver library queries them in the order
	// listed.  If no nameserver entries are present, the default is to
	// use the name server on the local machine.  (The algorithm used is
	// to try a name server, and if the query times out, try the next,
	// until out of name servers, then repeat trying all the name servers
	// until a maximum number of retries are made.)
	NameServers []string

	// Sets a threshold for the number of dots which must appear in a name
	// before an initial absolute query will be made.  The default for n
	// is 1, meaning that if there are any dots in a name, the name will
	// be tried first as an absolute name before any search list elements
	// are appended to it.  The value for this option is silently capped
	// to 15.
	NDots int

	// Sets the amount of time the resolver will wait for a response from
	// a remote name server before retrying the query via a different name
	// server. This may not be the total time taken by any resolver API
	// call and there is no guarantee that a single resolver API call maps
	// to a single timeout.  Measured in seconds, the default is 5 The
	// value for this option is silently capped to 30.
	Timeout int

	// Sets the number of times the resolver will send a query to its name
	// servers before giving up and returning an error to the calling
	// application.  The default is 2. The value for this option is
	// silently capped to 5.
	Attempts int

	// OptMisc contains other options with string key and boolean value.
	OptMisc map[string]bool
}

ResolvConf contains value of resolver configuration file.

Reference: "man resolv.conf" in Linux.

func NewResolvConf

func NewResolvConf(path string) (*ResolvConf, error)

NewResolvConf open resolv.conf file in path and return the parsed records.

func (*ResolvConf) Init

func (rc *ResolvConf) Init(src string)

Init parse resolv.conf from string.

type Type

type Type uint16

Type of network.

const (
	TypeInvalid Type = 0
	TypeTCP     Type = 1 << iota
	TypeTCP4
	TypeTCP6
	TypeUDP
	TypeUDP4
	TypeUDP6
	TypeIP
	TypeIP4
	TypeIP6
	TypeUnix
	TypeUnixGram
	TypeUnixPacket
)

List of possible network type.

func ConvertStandard

func ConvertStandard(network string) Type

ConvertStandard library network value from string to Type. It will return TypeInvalid (0) if network is unknown.

Directories

Path Synopsis
Package html extends the golang.org/x/net/html by providing simplified methods to Node.
Package html extends the golang.org/x/net/html by providing simplified methods to Node.

Jump to

Keyboard shortcuts

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