net

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: BSD-3-Clause Imports: 8 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) 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 (".").

See rfc952 and rfc1123.

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) (hostname string, ip net.IP, port uint16)

ParseIPPort parse address into IP and port. If address is not an IP address, it will the address as hostname (without port number if its exist) with 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.

Types

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.

Jump to

Keyboard shortcuts

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