Documentation ¶
Index ¶
- Constants
- Variables
- func AddrPortMappedEqual(l, r netip.AddrPort) bool
- func AddrPortToSockaddr(addrPort netip.AddrPort) (name *byte, namelen uint32)
- func AddrPortToSockaddrInet4(addrPort netip.AddrPort) unix.RawSockaddrInet4
- func AddrPortToSockaddrInet6(addrPort netip.AddrPort) unix.RawSockaddrInet6
- func AddrPortv4Mappedv6(addrPort netip.AddrPort) netip.AddrPort
- func DialTFOWithPayload(dialer *tfo.Dialer, address string, payload []byte) (n int, conn tfo.Conn, err error)
- func ListenUDP(network string, laddr string, pktinfo bool, fwmark int) (conn *net.UDPConn, err error, serr error)
- func NewDialer(dialerTFO bool, dialerFwmark int) (dialer tfo.Dialer)
- func NewListenConfig(listenerTFO bool, listenerFwmark int) (lc tfo.ListenConfig)
- func ParseFlagsForError(flags int) error
- func Recvmmsg(conn *net.UDPConn, msgvec []Mmsghdr) (n int, err error)
- func ResolveAddr(host string, preferIPv6 bool) (netip.Addr, error)
- func Sendmmsg(conn *net.UDPConn, msgvec []Mmsghdr) (n int, err error)
- func SockaddrToAddrPort(name *byte, namelen uint32) (netip.AddrPort, error)
- func UpdatePktinfoCache(pktinfoCache, cmsgs []byte, logger *zap.Logger) ([]byte, error)
- func WriteMsgvec(conn *net.UDPConn, msgvec []Mmsghdr) error
- type Addr
- func (a Addr) AppendTo(b []byte) []byte
- func (a Addr) Domain() string
- func (a Addr) Host() string
- func (a Addr) IP() netip.Addr
- func (a Addr) IPPort() netip.AddrPort
- func (a Addr) IsIP() bool
- func (a Addr) MappedEquals(b Addr) bool
- func (a Addr) MarshalText() ([]byte, error)
- func (a Addr) Port() uint16
- func (a Addr) ResolveIP(preferIPv6 bool) (netip.Addr, error)
- func (a Addr) ResolveIPPort(preferIPv6 bool) (netip.AddrPort, error)
- func (a Addr) String() string
- func (a *Addr) UnmarshalText(text []byte) error
- type Mmsghdr
Constants ¶
const SocketControlMessageBufferSize = 128
SocketControlMessageBufferSize specifies the buffer size for receiving socket control messages.
const UIO_MAXIOV = 1024
Source: include/uapi/linux/uio.h
Variables ¶
var ( ErrMessageTruncated = errors.New("the packet is larger than the supplied buffer") ErrControlMessageTruncated = errors.New("the control message is larger than the supplied buffer") )
Functions ¶
func AddrPortMappedEqual ¶ added in v1.1.0
AddrPortMappedEqual returns whether the two addresses point to the same endpoint. An IPv4 address and an IPv4-mapped IPv6 address pointing to the same endpoint are considered equal. For example, 1.1.1.1:53 and [::ffff:1.1.1.1]:53 are considered equal.
func AddrPortToSockaddr ¶
func AddrPortToSockaddrInet4 ¶
func AddrPortToSockaddrInet4(addrPort netip.AddrPort) unix.RawSockaddrInet4
func AddrPortToSockaddrInet6 ¶
func AddrPortToSockaddrInet6(addrPort netip.AddrPort) unix.RawSockaddrInet6
func AddrPortv4Mappedv6 ¶ added in v1.1.0
AddrPortv4Mappedv6 converts an IPv4 address to an IPv4-mapped IPv6 address. This function does nothing if addrPort is an IPv6 address.
func DialTFOWithPayload ¶
func DialTFOWithPayload(dialer *tfo.Dialer, address string, payload []byte) (n int, conn tfo.Conn, err error)
DialTFOWithPayload uses a TFO dialer to dial the target and writes the initial payload. TFO is disabled if initial payload is empty.
func ListenUDP ¶
func ListenUDP(network string, laddr string, pktinfo bool, fwmark int) (conn *net.UDPConn, err error, serr error)
ListenUDP wraps Go's net.ListenConfig.ListenPacket and sets socket options on supported platforms.
On Linux and Windows, IP_MTU_DISCOVER and IPV6_MTU_DISCOVER are set to IP_PMTUDISC_DO to disable IP fragmentation and encourage correct MTU settings. If pktinfo is true, IP_PKTINFO and IPV6_RECVPKTINFO are set to 1.
On Linux, SO_MARK is set to user-specified value.
On macOS and FreeBSD, IP_DONTFRAG, IPV6_DONTFRAG are set to 1 (Don't Fragment).
func NewListenConfig ¶
NewListenConfig returns a tfo.ListenConfig with the specified options applied.
func ParseFlagsForError ¶
ParseFlagsForError parses the message flags returned by the ReadMsgUDPAddrPort method and returns an error if MSG_TRUNC is set, indicating that the returned packet was truncated.
The check is skipped on Windows, because an error (WSAEMSGSIZE) is also returned when MSG_PARTIAL is set.
func ResolveAddr ¶
ResolveAddr resolves a domain name string into netip.Addr. String representations of IP addresses are not supported.
func SockaddrToAddrPort ¶
func UpdatePktinfoCache ¶ added in v1.2.0
On Linux and Windows, UpdatePktinfoCache filters out irrelevant socket control messages, saves IP_PKTINFO or IPV6_PKTINFO socket control messages to the pktinfo cache, and returns the updated pktinfo cache slice.
The returned pktinfo cache is unchanged if no relevant control messages are found.
On other platforms, this is a no-op.
func WriteMsgvec ¶
WriteMsgvec repeatedly calls sendmmsg(2) until all messages in msgvec are written to the socket.
If the syscall returns an error, this function drops the message that caused the error, and continues sending. Only the last encountered error is returned.
Types ¶
type Addr ¶ added in v1.1.0
type Addr struct {
// contains filtered or unexported fields
}
Addr is the base address type used throughout the package.
An Addr is a port number combined with either an IP address or a domain name.
func AddrFromDomainPort ¶ added in v1.1.0
AddrFromDomainPort returns an Addr from the provided domain name and port number.
func AddrFromHostPort ¶ added in v1.1.0
AddrFromHostPort returns an Addr from the provided host string and port number. The host string may be a string representation of an IP address or a domain name.
func AddrFromIPPort ¶ added in v1.1.0
AddrFromIPPort returns an Addr from the provided netip.AddrPort.
func MustAddrFromDomainPort ¶ added in v1.1.0
MustAddrFromDomainPort calls AddrFromDomainPort and panics on error.
func ParseAddr ¶ added in v1.1.0
ParseAddr parses the provided string representation of an address and returns the parsed address or an error.
func (Addr) AppendTo ¶ added in v1.1.0
AppendTo appends the string representation of the address to the provided buffer.
func (Addr) Domain ¶ added in v1.1.0
Domain returns the domain name. If the address is an IP address, the returned domain name is an empty string.
func (Addr) Host ¶ added in v1.1.0
Host returns the string representation of the IP address or the domain name.
func (Addr) IP ¶ added in v1.1.0
IP returns the IP address. If the address is a domain name, the returned netip.Addr is a zero value.
func (Addr) IPPort ¶ added in v1.1.0
IPPort returns a netip.AddrPort. If the address is a domain name, the returned netip.AddrPort contains a zero-value netip.Addr and the port number.
func (Addr) IsIP ¶ added in v1.1.0
IsIP returns whether the address is an IP address. If false, the address is a domain name.
func (Addr) MappedEquals ¶ added in v1.1.0
MappedEquals returns whether the two addresses point to the same endpoint. An IPv4 address and an IPv4-mapped IPv6 address pointing to the same endpoint are considered equal. For example, 1.1.1.1:53 and [::ffff:1.1.1.1]:53 are considered equal.
func (Addr) MarshalText ¶ added in v1.1.0
MarshalText implements the encoding.TextMarshaler MarshalText method.
func (Addr) ResolveIP ¶ added in v1.1.0
ResolveIP returns the IP address itself or the resolved IP address of the domain name.
func (Addr) ResolveIPPort ¶ added in v1.1.0
ResolveIPPort returns the IP address itself or the resolved IP address of the domain name and the port number as a netip.AddrPort.
func (*Addr) UnmarshalText ¶ added in v1.1.0
UnmarshalText implements the encoding.TextUnmarshaler UnmarshalText method.