Documentation
¶
Overview ¶
Package net contains common network utilities.
Index ¶
Constants ¶
const (
// TCPNetwork represents the TCP network.
TCPNetwork = Network("tcp")
// UDPNetwork represents the UDP network.
UDPNetwork = Network("udp")
)
Variables ¶
var (
// ErrorInvalidPortRage indicates an error during port range parsing.
ErrorInvalidPortRange = errors.New("Invalid port range.")
)
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address interface {
IP() net.IP // IP of this Address
Domain() string // Domain of this Address
IsIPv4() bool // True if this Address is an IPv4 address
IsIPv6() bool // True if this Address is an IPv6 address
IsDomain() bool // True if this Address is an domain address
String() string // String representation of this Address
Equals(Address) bool
}
Address represents a network address to be communicated with. It may be an IP address or domain address, not both. This interface doesn't resolve IP address for a given domain.
func DomainAddress ¶
func DomainAddress(domain string) Address
DomainAddress creates an Address with given domain.
func ParseAddress ¶ added in v1.9.1
func ParseAddress(addr string) Address
ParseAddress parses a string into an Address. The return value will be an IPAddress when the string is in the form of IPv4 or IPv6 address, or a DomainAddress otherwise.
type Destination ¶
type Destination interface {
Network() Network // Protocol of communication (tcp / udp)
Address() Address // Address of destination
Port() Port
String() string // String representation of the destination
NetAddr() string
Equals(Destination) bool
IsTCP() bool // True if destination is reachable via TCP
IsUDP() bool // True if destination is reachable via UDP
}
Destination represents a network destination including address and protocol (tcp / udp).
func TCPDestination ¶
func TCPDestination(address Address, port Port) Destination
TCPDestination creates a TCP destination with given address
func UDPDestination ¶
func UDPDestination(address Address, port Port) Destination
UDPDestination creates a UDP destination with given address
type IPNet ¶ added in v1.1.1
type IPNet struct {
// contains filtered or unexported fields
}
func NewIPNetInitialValue ¶ added in v1.1.1
func NewIPNetInitialValue(data map[uint32]byte) *IPNet
type Network ¶ added in v0.14.1
type Network serial.StringLiteral
Network represents a communication network on internet.
type NetworkList ¶ added in v0.14.1
type NetworkList []Network
NetworkList is a list of Networks.
func NewNetworkList ¶ added in v1.9.1
func NewNetworkList(networks serial.StringLiteralList) NetworkList
NewNetworkList construsts a NetWorklist from the given StringListeralList.
func (*NetworkList) HasNetwork ¶ added in v0.14.1
func (this *NetworkList) HasNetwork(network Network) bool
HashNetwork returns true if the given network is in this NetworkList.
type Port ¶ added in v1.1.1
type Port serial.Uint16Literal
Port represents a network port in TCP and UDP protocol.
func PortFromBytes ¶ added in v1.1.1
func PortFromBytes(port []byte) Port
PortFromBytes converts a byte array to a Port, assuming bytes are in big endian order. @unsafe Caller must ensure that the byte array has at least 2 elements.
func PortFromInt ¶ added in v1.9.1
func PortFromInt(v int) (Port, error)
PortFromInt converts an integer to a Port. @error when the integer is not positive or larger then 65535
func PortFromString ¶ added in v1.9.1
func PortFromString(s string) (Port, error)
PortFromString converts a string to a Port. @error when the string is not an integer or the integral value is a not a valid Port.
func (Port) Bytes ¶ added in v1.1.1
func (this Port) Bytes() []byte
Bytes returns the correspoding bytes of this Port, in big endian order.
type PortRange ¶ added in v0.14.1
type PortRange struct {
From Port
To Port
}
PortRange represents a range of ports.
type TimeOutReader ¶
type TimeOutReader struct {
// contains filtered or unexported fields
}
func NewTimeOutReader ¶
func NewTimeOutReader(timeout int, connection net.Conn) *TimeOutReader
func (*TimeOutReader) GetTimeOut ¶ added in v0.9.1
func (reader *TimeOutReader) GetTimeOut() int
func (*TimeOutReader) SetTimeOut ¶ added in v0.9.1
func (reader *TimeOutReader) SetTimeOut(value int)