Documentation ¶
Overview ¶
Package net provide constants and library for networking.
Index ¶
- Variables
- func IsHostnameValid(hname []byte, isFQDN bool) bool
- func IsIPv4(ip net.IP) bool
- func IsIPv6(ip net.IP) bool
- func IsTypeTCP(t Type) bool
- func IsTypeTransport(t Type) bool
- func IsTypeUDP(t Type) bool
- func ParseIPPort(address string, defPort uint16) (host string, ip net.IP, port uint16)
- func ParseTCPAddr(address string, defPort uint16) (udp *net.TCPAddr, err error)
- func ParseUDPAddr(address string, defPort uint16) (udp *net.UDPAddr, err error)
- func ToDotIPv6(ip net.IP) (out []byte)
- type Poll
- type ResolvConf
- type Type
Constants ¶
This section is empty.
Variables ¶
var (
ErrHostAddress = errors.New("invalid host address")
)
List of error messages.
Functions ¶
func IsHostnameValid ¶
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
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
IsIPv6 will return true if string representation of IP contains two or more colons ":", for example, "::1".
func IsTypeTCP ¶
IsTypeTCP will return true if t is type of TCP(4,6); otherwise it will return false.
func IsTypeTransport ¶
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 ¶
IsTypeUDP will return true if t is type of UDP(4,6); otherwise it will return false.
func ParseIPPort ¶
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 ¶
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 ¶
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 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.
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 ¶
ConvertStandard library network value from string to Type. It will return TypeInvalid (0) if network is unknown.