Documentation ¶
Index ¶
- Constants
- Variables
- func JoinHostPort(host, port string) string
- func LookupPort(network, service string) (port int, err error)
- func ParseCIDR(s string) (IP, *IPNet, error)
- func Pipe() (Conn, Conn)
- func SplitHostPort(hostport string) (host, port string, err error)
- type Addr
- type AddrError
- type Buffers
- type Conn
- type Dialer
- type Error
- type Flags
- type HardwareAddr
- type IP
- func (ip IP) DefaultMask() IPMask
- func (ip IP) Equal(x IP) bool
- func (ip IP) IsGlobalUnicast() bool
- func (ip IP) IsInterfaceLocalMulticast() bool
- func (ip IP) IsLinkLocalMulticast() bool
- func (ip IP) IsLinkLocalUnicast() bool
- func (ip IP) IsLoopback() bool
- func (ip IP) IsMulticast() bool
- func (ip IP) IsPrivate() bool
- func (ip IP) IsUnspecified() bool
- func (ip IP) MarshalText() ([]byte, error)
- func (ip IP) Mask(mask IPMask) IP
- func (ip IP) String() string
- func (ip IP) To16() IP
- func (ip IP) To4() IP
- func (ip *IP) UnmarshalText(text []byte) error
- type IPAddr
- type IPConn
- func (c *IPConn) Close() error
- func (c *IPConn) LocalAddr() Addr
- func (c *IPConn) ReadFrom(b []byte) (int, Addr, error)
- func (c *IPConn) ReadMsgIP(b, oob []byte) (n, oobn, flags int, addr *IPAddr, err error)
- func (c *IPConn) SetDeadline(t time.Time) error
- func (c *IPConn) SetReadDeadline(t time.Time) error
- func (c *IPConn) SetWriteDeadline(t time.Time) error
- func (c *IPConn) SyscallConn() (syscall.RawConn, error)
- func (c *IPConn) WriteTo(b []byte, addr Addr) (int, error)
- func (c *IPConn) WriteToIP(b []byte, addr *IPAddr) (int, error)
- type IPMask
- type IPNet
- type Interface
- type ListenConfig
- type Listener
- type OpError
- type PacketConn
- type ParseError
- type TCPAddr
- type TCPConn
- func (c *TCPConn) Close() error
- func (c *TCPConn) CloseWrite() error
- func (c *TCPConn) LocalAddr() Addr
- func (c *TCPConn) Read(b []byte) (int, error)
- func (c *TCPConn) RemoteAddr() Addr
- func (c *TCPConn) SetDeadline(t time.Time) error
- func (c *TCPConn) SetKeepAlive(keepalive bool) error
- func (c *TCPConn) SetKeepAlivePeriod(d time.Duration) error
- func (c *TCPConn) SetLinger(sec int) error
- func (c *TCPConn) SetReadDeadline(t time.Time) error
- func (c *TCPConn) SetWriteDeadline(t time.Time) error
- func (c *TCPConn) SyscallConn() (syscall.RawConn, error)
- func (c *TCPConn) Write(b []byte) (int, error)
- type TCPListener
- type TLSAddr
- type TLSConn
- func (c *TLSConn) Close() error
- func (c *TLSConn) Handshake() error
- func (c *TLSConn) LocalAddr() Addr
- func (c *TLSConn) Read(b []byte) (int, error)
- func (c *TLSConn) RemoteAddr() Addr
- func (c *TLSConn) SetDeadline(t time.Time) error
- func (c *TLSConn) SetReadDeadline(t time.Time) error
- func (c *TLSConn) SetWriteDeadline(t time.Time) error
- func (c *TLSConn) Write(b []byte) (int, error)
- type UDPAddr
- type UDPConn
- func (c *UDPConn) Close() error
- func (c *UDPConn) LocalAddr() Addr
- func (c *UDPConn) Read(b []byte) (int, error)
- func (c *UDPConn) ReadFrom(b []byte) (int, Addr, error)
- func (c *UDPConn) ReadMsgUDP(b, oob []byte) (n, oobn, flags int, addr *UDPAddr, err error)
- func (c *UDPConn) RemoteAddr() Addr
- func (c *UDPConn) SetDeadline(t time.Time) error
- func (c *UDPConn) SetReadDeadline(t time.Time) error
- func (c *UDPConn) SetWriteDeadline(t time.Time) error
- func (c *UDPConn) SyscallConn() (syscall.RawConn, error)
- func (c *UDPConn) Write(b []byte) (int, error)
- func (c *UDPConn) WriteMsgUDP(b, oob []byte, addr *UDPAddr) (n, oobn int, err error)
- func (c *UDPConn) WriteTo(b []byte, addr Addr) (int, error)
- type UnixAddr
- Bugs
Constants ¶
const ( IPv4len = 4 IPv6len = 16 )
IP address lengths (bytes).
Variables ¶
var ( IPv4bcast = IPv4(255, 255, 255, 255) // limited broadcast IPv4allsys = IPv4(224, 0, 0, 1) // all systems IPv4allrouter = IPv4(224, 0, 0, 2) // all routers IPv4zero = IPv4(0, 0, 0, 0) // all zeros )
Well-known IPv4 addresses
var ( IPv6zero = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} IPv6unspecified = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} IPv6loopback = IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} IPv6interfacelocalallnodes = IP{0xff, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01} IPv6linklocalallnodes = IP{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01} IPv6linklocalallrouters = IP{0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x02} )
Well-known IPv6 addresses
var ErrClosed error = errClosed
ErrClosed is the error returned by an I/O call on a network connection that has already been closed, or that is closed by another goroutine before the I/O is completed. This may be wrapped in another error, and should normally be tested using errors.Is(err, net.ErrClosed).
Functions ¶
func JoinHostPort ¶
JoinHostPort combines host and port into a network address of the form "host:port". If host contains a colon, as found in literal IPv6 addresses, then JoinHostPort returns "[host]:port".
See func Dial for a description of the host and port parameters.
func LookupPort ¶
LookupPort looks up the port for the given network and service.
LookupPort uses context.Background internally; to specify the context, use Resolver.LookupPort.
func ParseCIDR ¶
ParseCIDR parses s as a CIDR notation IP address and prefix length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
It returns the IP address and the network implied by the IP and prefix length. For example, ParseCIDR("192.0.2.1/24") returns the IP address 192.0.2.1 and the network 192.0.2.0/24.
func Pipe ¶
Pipe creates a synchronous, in-memory, full duplex network connection; both ends implement the Conn interface. Reads on one end are matched with writes on the other, copying data directly between the two; there is no internal buffering.
func SplitHostPort ¶
SplitHostPort splits a network address of the form "host:port", "host%zone:port", "[host]:port" or "[host%zone]:port" into host or host%zone and port.
A literal IPv6 address in hostport must be enclosed in square brackets, as in "[::1]:80", "[::1%lo0]:80".
See func Dial for a description of the hostport parameter, and host and port results.
Types ¶
type Addr ¶
type Addr interface { Network() string // name of the network (for example, "tcp", "udp") String() string // string form of address (for example, "192.0.2.1:25", "[2001:db8::1]:80") }
Addr represents a network end point address.
The two methods Network and String conventionally return strings that can be passed as the arguments to Dial, but the exact form and meaning of the strings is up to the implementation.
func InterfaceAddrs ¶
InterfaceAddrs returns a list of the system's unicast interface addresses.
The returned list does not identify the associated interface; use Interfaces and Interface.Addrs for more detail.
type Buffers ¶
type Buffers [][]byte
Buffers contains zero or more runs of bytes to write.
On certain machines, for certain types of connections, this is optimized into an OS-specific batch write operation (such as "writev").
type Conn ¶
type Conn interface { // Read reads data from the connection. // Read can be made to time out and return an error after a fixed // time limit; see SetDeadline and SetReadDeadline. Read(b []byte) (n int, err error) // Write writes data to the connection. // Write can be made to time out and return an error after a fixed // time limit; see SetDeadline and SetWriteDeadline. Write(b []byte) (n int, err error) // Close closes the connection. // Any blocked Read or Write operations will be unblocked and return errors. Close() error // LocalAddr returns the local network address, if known. LocalAddr() Addr // RemoteAddr returns the remote network address, if known. RemoteAddr() Addr // SetDeadline sets the read and write deadlines associated // with the connection. It is equivalent to calling both // SetReadDeadline and SetWriteDeadline. // // A deadline is an absolute time after which I/O operations // fail instead of blocking. The deadline applies to all future // and pending I/O, not just the immediately following call to // Read or Write. After a deadline has been exceeded, the // connection can be refreshed by setting a deadline in the future. // // If the deadline is exceeded a call to Read or Write or to other // I/O methods will return an error that wraps os.ErrDeadlineExceeded. // This can be tested using errors.Is(err, os.ErrDeadlineExceeded). // The error's Timeout method will return true, but note that there // are other possible errors for which the Timeout method will // return true even if the deadline has not been exceeded. // // An idle timeout can be implemented by repeatedly extending // the deadline after successful Read or Write calls. // // A zero value for t means I/O operations will not time out. SetDeadline(t time.Time) error // SetReadDeadline sets the deadline for future Read calls // and any currently-blocked Read call. // A zero value for t means Read will not time out. SetReadDeadline(t time.Time) error // SetWriteDeadline sets the deadline for future Write calls // and any currently-blocked Write call. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means Write will not time out. SetWriteDeadline(t time.Time) error }
Conn is a generic stream-oriented network connection.
Multiple goroutines may invoke methods on a Conn simultaneously.
func Dial ¶
Dial connects to the address on the named network.
See Go "net" package Dial() for more information.
Note: Tinygo Dial supports a subset of networks supported by Go Dial, specifically: "tcp", "tcp4", "udp", and "udp4". IP and unix networks are not supported.
func DialTimeout ¶
DialTimeout acts like Dial but takes a timeout.
The timeout includes name resolution, if required. When using TCP, and the host in the address parameter resolves to multiple IP addresses, the timeout is spread over each consecutive dial, such that each is given an appropriate fraction of the time to connect.
See func Dial for a description of the network and address parameters.
type Dialer ¶
type Dialer struct { // Timeout is the maximum amount of time a dial will wait for // a connect to complete. If Deadline is also set, it may fail // earlier. // // The default is no timeout. // // When using TCP and dialing a host name with multiple IP // addresses, the timeout may be divided between them. // // With or without a timeout, the operating system may impose // its own earlier timeout. For instance, TCP timeouts are // often around 3 minutes. Timeout time.Duration // Deadline is the absolute point in time after which dials // will fail. If Timeout is set, it may fail earlier. // Zero means no deadline, or dependent on the operating system // as with the Timeout option. Deadline time.Time // LocalAddr is the local address to use when dialing an // address. The address must be of a compatible type for the // network being dialed. // If nil, a local address is automatically chosen. LocalAddr Addr // KeepAlive specifies the interval between keep-alive // probes for an active network connection. // If zero, keep-alive probes are sent with a default value // (currently 15 seconds), if supported by the protocol and operating // system. Network protocols or operating systems that do // not support keep-alives ignore this field. // If negative, keep-alive probes are disabled. KeepAlive time.Duration }
A Dialer contains options for connecting to an address.
The zero value for each field is equivalent to dialing without that option. Dialing with the zero value of Dialer is therefore equivalent to just calling the Dial function.
It is safe to call Dialer's methods concurrently.
func (*Dialer) Dial ¶
Dial connects to the address on the named network.
See func Dial for a description of the network and address parameters.
Dial uses context.Background internally; to specify the context, use DialContext.
func (*Dialer) DialContext ¶
DialContext connects to the address on the named network using the provided context.
The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.
When using TCP, and the host in the address parameter resolves to multiple network addresses, any dial timeout (from d.Timeout or ctx) is spread over each consecutive dial, such that each is given an appropriate fraction of the time to connect. For example, if a host has 4 IP addresses and the timeout is 1 minute, the connect to each single address will be given 15 seconds to complete before trying the next one.
See func Dial for a description of the network and address parameters.
type Error ¶
type Error interface { error Timeout() bool // Is the error a timeout? // Deprecated: Temporary errors are not well-defined. // Most "temporary" errors are timeouts, and the few exceptions are surprising. // Do not use this method. Temporary() bool }
An Error represents a network error.
type Flags ¶
type Flags uint
const ( FlagUp Flags = 1 << iota // interface is administratively up FlagBroadcast // interface supports broadcast access capability FlagLoopback // interface is a loopback interface FlagPointToPoint // interface belongs to a point-to-point link FlagMulticast // interface supports multicast access capability FlagRunning // interface is in running state )
type HardwareAddr ¶
type HardwareAddr []byte
A HardwareAddr represents a physical hardware address.
func ParseMAC ¶
func ParseMAC(s string) (hw HardwareAddr, err error)
ParseMAC parses s as an IEEE 802 MAC-48, EUI-48, EUI-64, or a 20-octet IP over InfiniBand link-layer address using one of the following formats:
00:00:5e:00:53:01 02:00:5e:10:00:00:00:01 00:00:00:00:fe:80:00:00:00:00:00:00:02:00:5e:10:00:00:00:01 00-00-5e-00-53-01 02-00-5e-10-00-00-00-01 00-00-00-00-fe-80-00-00-00-00-00-00-02-00-5e-10-00-00-00-01 0000.5e00.5301 0200.5e10.0000.0001 0000.0000.fe80.0000.0000.0000.0200.5e10.0000.0001
func (HardwareAddr) String ¶
func (a HardwareAddr) String() string
type IP ¶
type IP []byte
An IP is a single IP address, a slice of bytes. Functions in this package accept either 4-byte (IPv4) or 16-byte (IPv6) slices as input.
Note that in this documentation, referring to an IP address as an IPv4 address or an IPv6 address is a semantic property of the address, not just the length of the byte slice: a 16-byte slice can still be an IPv4 address.
func ParseIP ¶
ParseIP parses s as an IP address, returning the result. The string s can be in IPv4 dotted decimal ("192.0.2.1"), IPv6 ("2001:db8::68"), or IPv4-mapped IPv6 ("::ffff:192.0.2.1") form. If s is not a valid textual representation of an IP address, ParseIP returns nil.
func (IP) DefaultMask ¶
DefaultMask returns the default IP mask for the IP address ip. Only IPv4 addresses have default masks; DefaultMask returns nil if ip is not a valid IPv4 address.
func (IP) Equal ¶
Equal reports whether ip and x are the same IP address. An IPv4 address and that same address in IPv6 form are considered to be equal.
func (IP) IsGlobalUnicast ¶
IsGlobalUnicast reports whether ip is a global unicast address.
The identification of global unicast addresses uses address type identification as defined in RFC 1122, RFC 4632 and RFC 4291 with the exception of IPv4 directed broadcast addresses. It returns true even if ip is in IPv4 private address space or local IPv6 unicast address space.
func (IP) IsInterfaceLocalMulticast ¶
IsInterfaceLocalMulticast reports whether ip is an interface-local multicast address.
func (IP) IsLinkLocalMulticast ¶
IsLinkLocalMulticast reports whether ip is a link-local multicast address.
func (IP) IsLinkLocalUnicast ¶
IsLinkLocalUnicast reports whether ip is a link-local unicast address.
func (IP) IsLoopback ¶
IsLoopback reports whether ip is a loopback address.
func (IP) IsMulticast ¶
IsMulticast reports whether ip is a multicast address.
func (IP) IsPrivate ¶
IsPrivate reports whether ip is a private address, according to RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses).
func (IP) IsUnspecified ¶
IsUnspecified reports whether ip is an unspecified address, either the IPv4 address "0.0.0.0" or the IPv6 address "::".
func (IP) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by String, with one exception: When len(ip) is zero, it returns an empty slice.
func (IP) String ¶
String returns the string form of the IP address ip. It returns one of 4 forms:
- "<nil>", if ip has length 0
- dotted decimal ("192.0.2.1"), if ip is an IPv4 or IP4-mapped IPv6 address
- IPv6 conforming to RFC 5952 ("2001:db8::1"), if ip is a valid IPv6 address
- the hexadecimal form of ip, without punctuation, if no other cases apply
func (IP) To16 ¶
To16 converts the IP address ip to a 16-byte representation. If ip is not an IP address (it is the wrong length), To16 returns nil.
func (IP) To4 ¶
To4 converts the IPv4 address ip to a 4-byte representation. If ip is not an IPv4 address, To4 returns nil.
func (*IP) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. The IP address is expected in a form accepted by ParseIP.
type IPAddr ¶
IPAddr represents the address of an IP end point.
type IPConn ¶
type IPConn struct {
// contains filtered or unexported fields
}
IPConn is the implementation of the Conn and PacketConn interfaces for IP network connections.
func (*IPConn) LocalAddr ¶
func (c *IPConn) LocalAddr() Addr
LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
func (*IPConn) ReadMsgIP ¶
ReadMsgIP reads a message from c, copying the payload into b and the associated out-of-band data into oob. It returns the number of bytes copied into b, the number of bytes copied into oob, the flags that were set on the message and the source address of the message.
The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob.
func (*IPConn) SetDeadline ¶
SetDeadline implements the Conn SetDeadline method.
func (*IPConn) SetReadDeadline ¶
SetReadDeadline implements the Conn SetReadDeadline method.
func (*IPConn) SetWriteDeadline ¶
SetWriteDeadline implements the Conn SetWriteDeadline method.
func (*IPConn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
type IPMask ¶
type IPMask []byte
An IPMask is a bitmask that can be used to manipulate IP addresses for IP addressing and routing.
See type IPNet and func ParseCIDR for details.
func CIDRMask ¶
CIDRMask returns an IPMask consisting of 'ones' 1 bits followed by 0s up to a total length of 'bits' bits. For a mask of this form, CIDRMask is the inverse of IPMask.Size.
type IPNet ¶
An IPNet represents an IP network.
func (*IPNet) String ¶
String returns the CIDR notation of n like "192.0.2.0/24" or "2001:db8::/48" as defined in RFC 4632 and RFC 4291. If the mask is not in the canonical form, it returns the string which consists of an IP address, followed by a slash character and a mask expressed as hexadecimal form with no punctuation like "198.51.100.0/c000ff00".
type Interface ¶
type Interface struct { Index int // positive integer that starts at one, zero is never used MTU int // maximum transmission unit Name string // e.g., "en0", "lo0", "eth0.100" HardwareAddr HardwareAddr // IEEE MAC-48, EUI-48 and EUI-64 form Flags Flags // e.g., FlagUp, FlagLoopback, FlagMulticast }
Interface represents a mapping between network interface name and index. It also represents network interface facility information.
func InterfaceByIndex ¶
InterfaceByIndex returns the interface specified by index.
On Solaris, it returns one of the logical network interfaces sharing the logical data link; for more precision use InterfaceByName.
func Interfaces ¶
Interfaces returns a list of the system's network interfaces.
type ListenConfig ¶
type ListenConfig struct { // If Control is not nil, it is called after creating the network // connection but before binding it to the operating system. // // Network and address parameters passed to Control method are not // necessarily the ones passed to Listen. For example, passing "tcp" to // Listen will cause the Control function to be called with "tcp4" or "tcp6". Control func(network, address string, c syscall.RawConn) error // KeepAlive specifies the keep-alive period for network // connections accepted by this listener. // If zero, keep-alives are enabled if supported by the protocol // and operating system. Network protocols or operating systems // that do not support keep-alives ignore this field. // If negative, keep-alives are disabled. KeepAlive time.Duration // contains filtered or unexported fields }
ListenConfig contains options for listening to an address.
func (*ListenConfig) Listen ¶
Listen announces on the local network address.
See func Listen for a description of the network and address parameters.
func (*ListenConfig) ListenPacket ¶
func (lc *ListenConfig) ListenPacket(ctx context.Context, network, address string) (PacketConn, error)
ListenPacket announces on the local network address.
See func ListenPacket for a description of the network and address parameters.
type Listener ¶
type Listener interface { // Accept waits for and returns the next connection to the listener. Accept() (Conn, error) // Close closes the listener. // Any blocked Accept operations will be unblocked and return errors. Close() error // Addr returns the listener's network address. Addr() Addr }
A Listener is a generic network listener for stream-oriented protocols.
Multiple goroutines may invoke methods on a Listener simultaneously.
type OpError ¶
type OpError struct { // Op is the operation which caused the error, such as // "read" or "write". Op string // Net is the network type on which this error occurred, // such as "tcp" or "udp6". Net string // For operations involving a remote network connection, like // Dial, Read, or Write, Source is the corresponding local // network address. Source Addr // Addr is the network address for which this error occurred. // For local operations, like Listen or SetDeadline, Addr is // the address of the local endpoint being manipulated. // For operations involving a remote network connection, like // Dial, Read, or Write, Addr is the remote address of that // connection. Addr Addr // Err is the error that occurred during the operation. // The Error method panics if the error is nil. Err error }
OpError is the error type usually returned by functions in the net package. It describes the operation, network type, and address of an error.
type PacketConn ¶
type PacketConn interface { // ReadFrom reads a packet from the connection, // copying the payload into p. It returns the number of // bytes copied into p and the return address that // was on the packet. // It returns the number of bytes read (0 <= n <= len(p)) // and any error encountered. Callers should always process // the n > 0 bytes returned before considering the error err. // ReadFrom can be made to time out and return an error after a // fixed time limit; see SetDeadline and SetReadDeadline. ReadFrom(p []byte) (n int, addr Addr, err error) // WriteTo writes a packet with payload p to addr. // WriteTo can be made to time out and return an Error after a // fixed time limit; see SetDeadline and SetWriteDeadline. // On packet-oriented connections, write timeouts are rare. WriteTo(p []byte, addr Addr) (n int, err error) // Close closes the connection. // Any blocked ReadFrom or WriteTo operations will be unblocked and return errors. Close() error // LocalAddr returns the local network address, if known. LocalAddr() Addr // SetDeadline sets the read and write deadlines associated // with the connection. It is equivalent to calling both // SetReadDeadline and SetWriteDeadline. // // A deadline is an absolute time after which I/O operations // fail instead of blocking. The deadline applies to all future // and pending I/O, not just the immediately following call to // Read or Write. After a deadline has been exceeded, the // connection can be refreshed by setting a deadline in the future. // // If the deadline is exceeded a call to Read or Write or to other // I/O methods will return an error that wraps os.ErrDeadlineExceeded. // This can be tested using errors.Is(err, os.ErrDeadlineExceeded). // The error's Timeout method will return true, but note that there // are other possible errors for which the Timeout method will // return true even if the deadline has not been exceeded. // // An idle timeout can be implemented by repeatedly extending // the deadline after successful ReadFrom or WriteTo calls. // // A zero value for t means I/O operations will not time out. SetDeadline(t time.Time) error // SetReadDeadline sets the deadline for future ReadFrom calls // and any currently-blocked ReadFrom call. // A zero value for t means ReadFrom will not time out. SetReadDeadline(t time.Time) error // SetWriteDeadline sets the deadline for future WriteTo calls // and any currently-blocked WriteTo call. // Even if write times out, it may return n > 0, indicating that // some of the data was successfully written. // A zero value for t means WriteTo will not time out. SetWriteDeadline(t time.Time) error }
PacketConn is a generic packet-oriented network connection.
Multiple goroutines may invoke methods on a PacketConn simultaneously.
type ParseError ¶
type ParseError struct { // Type is the type of string that was expected, such as // "IP address", "CIDR address". Type string // Text is the malformed text string. Text string }
A ParseError is the error type of literal network address parsers.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type TCPAddr ¶
TCPAddr represents the address of a TCP end point.
func ResolveTCPAddr ¶
ResolveTCPAddr returns an address of TCP end point.
The network must be a TCP network name.
If the host in the address parameter is not a literal IP address or the port is not a literal port number, ResolveTCPAddr resolves the address to an address of TCP end point. Otherwise, it parses the address as a pair of literal IP address and port number. The address parameter can use a host name, but this is not recommended, because it will return at most one of the host name's IP addresses.
See func Dial for a description of the network and address parameters.
func TCPAddrFromAddrPort ¶
TCPAddrFromAddrPort returns addr as a TCPAddr. If addr.IsValid() is false, then the returned TCPAddr will contain a nil IP field, indicating an address family-agnostic unspecified address.
func (*TCPAddr) AddrPort ¶
AddrPort returns the TCPAddr a as a netip.AddrPort.
If a.Port does not fit in a uint16, it's silently truncated.
If a is nil, a zero value is returned.
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
TCPConn is an implementation of the Conn interface for TCP network connections.
func DialTCP ¶
DialTCP acts like Dial for TCP networks.
The network must be a TCP network name; see func Dial for details.
If laddr is nil, a local address is automatically chosen. If the IP field of raddr is nil or an unspecified IP address, the local system is assumed.
func (*TCPConn) CloseWrite ¶
func (*TCPConn) RemoteAddr ¶
func (*TCPConn) SetKeepAlive ¶
SetKeepAlive sets whether the operating system should send keep-alive messages on the connection.
func (*TCPConn) SetKeepAlivePeriod ¶
SetKeepAlivePeriod sets period between keep-alives.
func (*TCPConn) SetLinger ¶
SetLinger sets the behavior of Close on a connection which still has data waiting to be sent or to be acknowledged.
If sec < 0 (the default), the operating system finishes sending the data in the background.
If sec == 0, the operating system discards any unsent or unacknowledged data.
If sec > 0, the data is sent in the background as with sec < 0. On some operating systems including Linux, this may cause Close to block until all data has been sent or discarded. On some operating systems after sec seconds have elapsed any remaining unsent data may be discarded.
func (*TCPConn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
type TCPListener ¶
type TCPListener struct {
// contains filtered or unexported fields
}
TCPListener is a TCP network listener. Clients should typically use variables of type Listener instead of assuming TCP.
type TLSConn ¶
type TLSConn struct {
// contains filtered or unexported fields
}
A TLSConn represents a secured connection. It implements the net.Conn interface.
func (*TLSConn) Handshake ¶
Handshake runs the client or server handshake protocol if it has not yet been run.
Most uses of this package need not call Handshake explicitly: the first Read or Write will call it automatically.
For control over canceling or setting a timeout on a handshake, use HandshakeContext or the Dialer's DialContext method instead.
func (*TLSConn) RemoteAddr ¶
type UDPAddr ¶
UDPAddr represents the address of a UDP end point.
func ResolveUDPAddr ¶
ResolveUDPAddr returns an address of UDP end point.
The network must be a UDP network name.
If the host in the address parameter is not a literal IP address or the port is not a literal port number, ResolveUDPAddr resolves the address to an address of UDP end point. Otherwise, it parses the address as a pair of literal IP address and port number. The address parameter can use a host name, but this is not recommended, because it will return at most one of the host name's IP addresses.
See func Dial for a description of the network and address parameters.
func (*UDPAddr) AddrPort ¶
AddrPort returns the UDPAddr a as a netip.AddrPort.
If a.Port does not fit in a uint16, it's silently truncated.
If a is nil, a zero value is returned.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections.
func DialUDP ¶
DialUDP acts like Dial for UDP networks.
The network must be a UDP network name; see func Dial for details.
If laddr is nil, a local address is automatically chosen. If the IP field of raddr is nil or an unspecified IP address, the local system is assumed.
func (*UDPConn) ReadMsgUDP ¶
ReadMsgUDP reads a message from c, copying the payload into b and the associated out-of-band data into oob. It returns the number of bytes copied into b, the number of bytes copied into oob, the flags that were set on the message and the source address of the message.
The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob.
func (*UDPConn) RemoteAddr ¶
func (*UDPConn) SyscallConn ¶
SyscallConn returns a raw network connection. This implements the syscall.Conn interface.
func (*UDPConn) WriteMsgUDP ¶
WriteMsgUDP writes a message to addr via c if c isn't connected, or to c's remote address if c is connected (in which case addr must be nil). The payload is copied from b and the associated out-of-band data is copied from oob. It returns the number of payload and out-of-band bytes written.
The packages golang.org/x/net/ipv4 and golang.org/x/net/ipv6 can be used to manipulate IP-level socket options in oob.
type UnixAddr ¶
UnixAddr represents the address of a Unix domain socket end point.
func ResolveUnixAddr ¶
ResolveUnixAddr returns an address of Unix domain socket end point.
The network must be a Unix network name.
See func Dial for a description of the network and address parameters.
Notes ¶
Bugs ¶
On JS, methods and functions related to Interface are not implemented.
On AIX, DragonFly BSD, NetBSD, OpenBSD, Plan 9 and Solaris, the MulticastAddrs method of Interface is not implemented.
On every POSIX platform, reads from the "ip4" network using the ReadFrom or ReadFromIP method might not return a complete IPv4 packet, including its header, even if there is space available. This can occur even in cases where Read or ReadMsgIP could return a complete packet. For this reason, it is recommended that you do not use these methods if it is important to receive a full packet.
The Go 1 compatibility guidelines make it impossible for us to change the behavior of these methods; use Read or ReadMsgIP instead.
On JS and Plan 9, methods and functions related to IPConn are not implemented.
On Windows, the File method of IPConn is not implemented.
On JS, WASIP1 and Plan 9, methods and functions related to UnixConn and UnixListener are not implemented.
On Windows, methods and functions related to UnixConn and UnixListener don't work for "unixgram" and "unixpacket".
On TinyGo, Unix sockets are not implemented.