Documentation
¶
Index ¶
- Constants
- Variables
- func AddressestoNetIPs(addrs []Address) ([]net.IP, error)
- func Checksum(sum uint32, b []byte) (answer [2]byte)
- func Contains(p *PortRange, port Port) bool
- func FetchHTTPContent(target string) ([]byte, error)
- func GetInnerMostConn(conn net.Conn) net.Conn
- func IPToNetipAddr(ip net.IP) netip.Addr
- func IntToIP(ip int) net.IP
- func IpToInt(ip net.IP) int
- func IsDirectedBoradcast(ip net.IP) bool
- func IsDomainTooLong(domain string) bool
- func NetIPFromGvisorTcpipAddress(address tcpip.Address) net.IP
- func NewConnection(opts ...ConnectionOption) net.Conn
- func PickUDPPort() uint16
- func PrefixStringFromIP(ip net.IP) string
- func RandomIP(startIP, endIP net.IP) net.IP
- func StandardIp(ip net.IP) net.IP
- func Sum(b []byte) uint32
- func SystemString(n Network) string
- func UnmarshalJSON(n *Network, b []byte) error
- type Addr
- type AddrError
- type Address
- type AddressFamily
- type AddressPort
- type BytesConn
- type Conn
- type ConnWithClose
- type ConnectionOption
- func ConnectionInput(writer io.Writer) ConnectionOption
- func ConnectionInputMulti(writer buf.Writer) ConnectionOption
- func ConnectionLocalAddr(a net.Addr) ConnectionOption
- func ConnectionOnClose(n io.Closer) ConnectionOption
- func ConnectionOutput(reader io.Reader) ConnectionOption
- func ConnectionOutputMulti(reader buf.Reader) ConnectionOption
- func ConnectionOutputMultiUDP(reader buf.Reader) ConnectionOption
- func ConnectionRemoteAddr(a net.Addr) ConnectionOption
- type Destination
- type Dialer
- type Error
- type HasNetConn
- type IP
- type IPMask
- type IPNet
- type ListenConfig
- type Listener
- type MbConn
- type MemoryConn
- func (c *MemoryConn) History() buf.MultiBuffer
- func (c *MemoryConn) OkayToUnwrapReader() int
- func (c *MemoryConn) OkayToUnwrapWriter() int
- func (c *MemoryConn) Read(p []byte) (int, error)
- func (c *MemoryConn) StopMemorize()
- func (c *MemoryConn) UnwrapReader() any
- func (c *MemoryConn) UnwrapWriter() any
- type NetConnToPacketConn
- type NetDialer
- type NetPacketListener
- type Network
- type PacketConn
- type Port
- type PortRange
- type Resolver
- type StatsConn
- type StatsListener
- type StatsPacketConn
- type TCPAddr
- type TCPConn
- type TCPListener
- type UDPAddr
- type UDPConn
- type UnixAddr
- type UnixConn
- type UnixListener
Constants ¶
const ( // AddressFamilyIPv4 represents address as IPv4 AddressFamilyIPv4 = AddressFamily(0) // AddressFamilyIPv6 represents address as IPv6 AddressFamilyIPv6 = AddressFamily(1) // AddressFamilyDomain represents address as Domain AddressFamilyDomain = AddressFamily(2) )
const ( IPv4len = net.IPv4len IPv6len = net.IPv6len )
Variables ¶
var ( // LocalHostIP is a constant value for localhost IP in IPv4. LocalHostIP = IPAddress([]byte{127, 0, 0, 1}) // AnyIP is a constant value for any IP in IPv4. AnyIP = IPAddress([]byte{0, 0, 0, 0}) // LocalHostDomain is a constant value for localhost domain. LocalHostDomain = DomainAddress("localhost") // LocalHostIPv6 is a constant value for localhost IP in IPv6. LocalHostIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}) // AnyIPv6 is a constant value for any IP in IPv6. AnyIPv6 = IPAddress([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) AliyunDns4 = IPAddress([]byte{223, 5, 5, 5}) CfDns4 = IPAddress([]byte{1, 1, 1, 1}) GoogleDns4 = IPAddress([]byte{8, 8, 8, 8}) )
var ( CIDRMask = net.CIDRMask Dial = net.Dial DialTCP = net.DialTCP DialUDP = net.DialUDP DialUnix = net.DialUnix FileConn = net.FileConn Listen = net.Listen ListenTCP = net.ListenTCP ListenUDP = net.ListenUDP ListenUnix = net.ListenUnix LookupIP = net.LookupIP ParseCIDR = net.ParseCIDR ParseIP = net.ParseIP ResolveUDPAddr = net.ResolveUDPAddr ResolveUnixAddr = net.ResolveUnixAddr SplitHostPort = net.SplitHostPort ResolveTCPAddr = net.ResolveTCPAddr )
var AnyUdpDest = Destination{ Address: AnyIP, Network: Network_UDP, }
var (
PrivateAddress = netip.PrefixFrom(netip.AddrFrom4([4]byte{172, 16, 0, 0}), 12)
)
Functions ¶
func Contains ¶ added in v1.1.2
Contains returns true if the given port is within the range of a PortRange.
func FetchHTTPContent ¶
FetchHTTPContent dials http(s) for remote content
func IsDirectedBoradcast ¶
func IsDomainTooLong ¶
func NewConnection ¶
func NewConnection(opts ...ConnectionOption) net.Conn
func PrefixStringFromIP ¶
func SystemString ¶ added in v1.1.2
func UnmarshalJSON ¶ added in v1.1.2
Types ¶
type Address ¶
type Address interface {
IP() net.IP // IP of this Address
Domain() string // Domain of this Address
Family() AddressFamily
// IPv6 address is wrapped in "[]"
String() string // String representation of this Address
}
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 AddressFromNetIpAddr ¶
func DomainAddress ¶
DomainAddress creates an Address with given domain.
func ParseAddress ¶
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.
func ParseIPFromString ¶
type AddressFamily ¶
type AddressFamily byte
AddressFamily is the type of address.
func (AddressFamily) IsDomain ¶
func (af AddressFamily) IsDomain() bool
IsDomain returns true if current AddressFamily is Domain.
func (AddressFamily) IsIP ¶
func (af AddressFamily) IsIP() bool
IsIP returns true if current AddressFamily is IPv6 or IPv4.
func (AddressFamily) IsIPv4 ¶
func (af AddressFamily) IsIPv4() bool
IsIPv4 returns true if current AddressFamily is IPv4.
func (AddressFamily) IsIPv6 ¶
func (af AddressFamily) IsIPv6() bool
IsIPv6 returns true if current AddressFamily is IPv6.
type AddressPort ¶
func (AddressPort) String ¶
func (ap AddressPort) String() string
type ConnWithClose ¶
func NewConnWithClose ¶
func NewConnWithClose(conn net.Conn, cb func()) *ConnWithClose
func (*ConnWithClose) Close ¶
func (c *ConnWithClose) Close() error
type ConnectionOption ¶
type ConnectionOption func(*connection)
func ConnectionInput ¶
func ConnectionInput(writer io.Writer) ConnectionOption
func ConnectionInputMulti ¶
func ConnectionInputMulti(writer buf.Writer) ConnectionOption
func ConnectionLocalAddr ¶
func ConnectionLocalAddr(a net.Addr) ConnectionOption
func ConnectionOnClose ¶
func ConnectionOnClose(n io.Closer) ConnectionOption
func ConnectionOutput ¶
func ConnectionOutput(reader io.Reader) ConnectionOption
func ConnectionOutputMulti ¶
func ConnectionOutputMulti(reader buf.Reader) ConnectionOption
func ConnectionOutputMultiUDP ¶
func ConnectionOutputMultiUDP(reader buf.Reader) ConnectionOption
func ConnectionRemoteAddr ¶
func ConnectionRemoteAddr(a net.Addr) ConnectionOption
type Destination ¶
Destination represents a network destination including address and protocol (tcp / udp).
func DestinationFromAddr ¶
func DestinationFromAddr(addr net.Addr) Destination
DestinationFromAddr generates a Destination from a net address.
func ParseDestination ¶
func ParseDestination(dest string) (Destination, error)
ParseDestination converts a destination from its string presentation.
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
func UnixDestination ¶
func UnixDestination(address Address) Destination
UnixDestination creates a Unix destination with given address
func (*Destination) Addr ¶
func (d *Destination) Addr() net.Addr
func (Destination) IsValid ¶
func (d Destination) IsValid() bool
IsValid returns true if this Destination is valid, i.e. it is not unknown
func (Destination) NetAddr ¶
func (d Destination) NetAddr() string
NetAddr returns the network address in this Destination in string form.
func (Destination) String ¶
func (d Destination) String() string
String returns the strings form of this Destination.
func (Destination) ToAddressPort ¶
func (t Destination) ToAddressPort() AddressPort
func (Destination) ToUdpNetwork ¶
func (t Destination) ToUdpNetwork() string
type HasNetConn ¶
type ListenConfig ¶
type ListenConfig = net.ListenConfig
type MbConn ¶
type MbConn struct {
net.Conn
Mb buf.MultiBuffer
}
read will read from Mb first
func (*MbConn) CloseWrite ¶
func (*MbConn) OkayToUnwrapReader ¶
func (*MbConn) OkayToUnwrapWriter ¶
func (*MbConn) UnwrapReader ¶
func (*MbConn) UnwrapWriter ¶
type MemoryConn ¶
all data read from Conn will be saved to history until stop
func NewMemoryRConn ¶
func NewMemoryRConn(conn net.Conn) *MemoryConn
func (*MemoryConn) History ¶
func (c *MemoryConn) History() buf.MultiBuffer
func (*MemoryConn) OkayToUnwrapReader ¶
func (c *MemoryConn) OkayToUnwrapReader() int
func (*MemoryConn) OkayToUnwrapWriter ¶
func (c *MemoryConn) OkayToUnwrapWriter() int
func (*MemoryConn) StopMemorize ¶
func (c *MemoryConn) StopMemorize()
func (*MemoryConn) UnwrapReader ¶
func (c *MemoryConn) UnwrapReader() any
func (*MemoryConn) UnwrapWriter ¶
func (c *MemoryConn) UnwrapWriter() any
type NetConnToPacketConn ¶
func (*NetConnToPacketConn) ReadFrom ¶
func (c *NetConnToPacketConn) ReadFrom(p []byte) (n int, addr Addr, err error)
func (*NetConnToPacketConn) SetReadBuffer ¶ added in v1.0.2
func (c *NetConnToPacketConn) SetReadBuffer(bytes int) error
suppress quic-go log
type NetPacketListener ¶
type NetPacketListener struct {
net.ListenConfig
}
func (*NetPacketListener) ListenPacket ¶
func (l *NetPacketListener) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
type PacketConn ¶
type PacketConn = net.PacketConn
type Port ¶
type Port uint16
Port represents a network port in TCP and UDP protocol.
func PortFromBytes ¶
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 ¶
PortFromInt converts an integer to a Port. @error when the integer is not positive or larger then 65535
func PortFromString ¶
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.
type PortRange ¶
func SinglePortRange ¶
SinglePortRange returns a PortRange contains a single port.
type StatsListener ¶
func NewStatsListener ¶
func NewStatsListener(listener net.Listener, readCounter, writeCounter *atomic.Uint64) *StatsListener
type StatsPacketConn ¶
type StatsPacketConn struct {
net.PacketConn
ReadCounter *atomic.Uint64
WriteCounter *atomic.Uint64
}
func NewStatsPacketConn ¶
func NewStatsPacketConn(pc net.PacketConn, readCounter, writeCounter *atomic.Uint64) *StatsPacketConn
type TCPListener ¶
type TCPListener = net.TCPListener
type UnixListener ¶
type UnixListener = net.UnixListener