Documentation ¶
Overview ¶
Package net is a drop-in replacement to Golang's net package, with some more functionalities.
Index ¶
- Constants
- Variables
- func HasNetwork(list []Network, network Network) bool
- func NewConnection(opts ...ConnectionOption) net.Conn
- type Addr
- type AddrError
- type Address
- type AddressFamily
- type Conn
- 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 ConnectionRemoteAddr(a net.Addr) ConnectionOption
- type Destination
- type Dialer
- type Endpoint
- func (p *Endpoint) AsDestination() Destination
- func (*Endpoint) Descriptor() ([]byte, []int)
- func (m *Endpoint) GetAddress() *IPOrDomain
- func (m *Endpoint) GetNetwork() Network
- func (m *Endpoint) GetPort() uint32
- func (*Endpoint) ProtoMessage()
- func (m *Endpoint) Reset()
- func (m *Endpoint) String() string
- func (m *Endpoint) XXX_DiscardUnknown()
- func (m *Endpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Endpoint) XXX_Merge(src proto.Message)
- func (m *Endpoint) XXX_Size() int
- func (m *Endpoint) XXX_Unmarshal(b []byte) error
- type Error
- type IP
- type IPMask
- type IPNet
- type IPNetTable
- type IPOrDomain
- func (d *IPOrDomain) AsAddress() Address
- func (*IPOrDomain) Descriptor() ([]byte, []int)
- func (m *IPOrDomain) GetAddress() isIPOrDomain_Address
- func (m *IPOrDomain) GetDomain() string
- func (m *IPOrDomain) GetIp() []byte
- func (*IPOrDomain) ProtoMessage()
- func (m *IPOrDomain) Reset()
- func (m *IPOrDomain) String() string
- func (m *IPOrDomain) XXX_DiscardUnknown()
- func (m *IPOrDomain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *IPOrDomain) XXX_Merge(src proto.Message)
- func (*IPOrDomain) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, ...)
- func (m *IPOrDomain) XXX_Size() int
- func (m *IPOrDomain) XXX_Unmarshal(b []byte) error
- type IPOrDomain_Domain
- type IPOrDomain_Ip
- type ListenConfig
- type Listener
- type Network
- type NetworkList
- func (*NetworkList) Descriptor() ([]byte, []int)
- func (l NetworkList) Get(idx int) Network
- func (m *NetworkList) GetNetwork() []Network
- func (l NetworkList) HasNetwork(network Network) bool
- func (*NetworkList) ProtoMessage()
- func (m *NetworkList) Reset()
- func (l NetworkList) Size() int
- func (m *NetworkList) String() string
- func (m *NetworkList) XXX_DiscardUnknown()
- func (m *NetworkList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *NetworkList) XXX_Merge(src proto.Message)
- func (m *NetworkList) XXX_Size() int
- func (m *NetworkList) XXX_Unmarshal(b []byte) error
- type PacketConn
- type Port
- type PortRange
- func (p PortRange) Contains(port Port) bool
- func (*PortRange) Descriptor() ([]byte, []int)
- func (p PortRange) FromPort() Port
- func (m *PortRange) GetFrom() uint32
- func (m *PortRange) GetTo() uint32
- func (*PortRange) ProtoMessage()
- func (m *PortRange) Reset()
- func (m *PortRange) String() string
- func (p PortRange) ToPort() Port
- func (m *PortRange) XXX_DiscardUnknown()
- func (m *PortRange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PortRange) XXX_Merge(src proto.Message)
- func (m *PortRange) XXX_Size() int
- func (m *PortRange) XXX_Unmarshal(b []byte) error
- type Resolver
- 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) )
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}) )
DialTCP is an injectable function. Default to net.DialTCP
var ListenUnix = net.ListenUnix
var ResolveUnixAddr = net.ResolveUnixAddr
var SplitHostPort = net.SplitHostPort
Functions ¶
func NewConnection ¶
func NewConnection(opts ...ConnectionOption) net.Conn
Types ¶
type Address ¶
type Address interface { IP() net.IP // IP of this Address Domain() string // Domain of this Address Family() AddressFamily 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 DomainAddress ¶
DomainAddress creates an Address with given domain.
type AddressFamily ¶ added in v1.24.1
type AddressFamily byte
AddressFamily is the type of address.
func (AddressFamily) Either ¶ added in v1.24.1
func (af AddressFamily) Either(fs ...AddressFamily) bool
Either returns true if current AddressFamily matches any of the AddressFamilies provided.
func (AddressFamily) IsDomain ¶ added in v1.24.1
func (af AddressFamily) IsDomain() bool
IsDomain returns true if current AddressFamily is Domain.
func (AddressFamily) IsIPv4 ¶ added in v1.24.1
func (af AddressFamily) IsIPv4() bool
IsIPv4 returns true if current AddressFamily is IPv4.
func (AddressFamily) IsIPv6 ¶ added in v1.24.1
func (af AddressFamily) IsIPv6() bool
IsIPv6 returns true if current AddressFamily is IPv6.
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 ConnectionRemoteAddr ¶
func ConnectionRemoteAddr(a net.Addr) ConnectionOption
type Destination ¶
Destination represents a network destination including address and protocol (tcp / udp).
func DestinationFromAddr ¶ added in v1.24.1
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 (Destination) IsValid ¶
func (d Destination) IsValid() bool
IsValid returns true if this Destination is valid.
func (Destination) NetAddr ¶ added in v1.9.1
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.
type Endpoint ¶
type Endpoint struct { Network Network `protobuf:"varint,1,opt,name=network,proto3,enum=v2ray.core.common.net.Network" json:"network,omitempty"` Address *IPOrDomain `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` Port uint32 `protobuf:"varint,3,opt,name=port,proto3" json:"port,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
Endpoint of a network connection.
func (*Endpoint) AsDestination ¶
func (p *Endpoint) AsDestination() Destination
AsDestination converts current Endpoint into Destination.
func (*Endpoint) GetAddress ¶
func (m *Endpoint) GetAddress() *IPOrDomain
func (*Endpoint) XXX_Marshal ¶
type IPNetTable ¶
type IPNetTable struct {
// contains filtered or unexported fields
}
func NewIPNetTable ¶
func NewIPNetTable() *IPNetTable
func (*IPNetTable) Add ¶
func (n *IPNetTable) Add(ipNet *net.IPNet)
func (*IPNetTable) AddIP ¶
func (n *IPNetTable) AddIP(ip []byte, mask byte)
func (*IPNetTable) Contains ¶
func (n *IPNetTable) Contains(ip net.IP) bool
func (*IPNetTable) IsEmpty ¶
func (n *IPNetTable) IsEmpty() bool
type IPOrDomain ¶
type IPOrDomain struct { // Types that are valid to be assigned to Address: // *IPOrDomain_Ip // *IPOrDomain_Domain Address isIPOrDomain_Address `protobuf_oneof:"address"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
Address of a network host. It may be either an IP address or a domain address.
func NewIPOrDomain ¶
func NewIPOrDomain(addr Address) *IPOrDomain
NewIPOrDomain translates Address to IPOrDomain
func (*IPOrDomain) AsAddress ¶
func (d *IPOrDomain) AsAddress() Address
AsAddress translates IPOrDomain to Address.
func (*IPOrDomain) Descriptor ¶
func (*IPOrDomain) Descriptor() ([]byte, []int)
func (*IPOrDomain) GetAddress ¶
func (m *IPOrDomain) GetAddress() isIPOrDomain_Address
func (*IPOrDomain) GetDomain ¶
func (m *IPOrDomain) GetDomain() string
func (*IPOrDomain) GetIp ¶
func (m *IPOrDomain) GetIp() []byte
func (*IPOrDomain) ProtoMessage ¶
func (*IPOrDomain) ProtoMessage()
func (*IPOrDomain) Reset ¶
func (m *IPOrDomain) Reset()
func (*IPOrDomain) String ¶
func (m *IPOrDomain) String() string
func (*IPOrDomain) XXX_DiscardUnknown ¶
func (m *IPOrDomain) XXX_DiscardUnknown()
func (*IPOrDomain) XXX_Marshal ¶
func (m *IPOrDomain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*IPOrDomain) XXX_Merge ¶
func (m *IPOrDomain) XXX_Merge(src proto.Message)
func (*IPOrDomain) XXX_OneofFuncs ¶
func (*IPOrDomain) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{})
XXX_OneofFuncs is for the internal use of the proto package.
func (*IPOrDomain) XXX_Size ¶
func (m *IPOrDomain) XXX_Size() int
func (*IPOrDomain) XXX_Unmarshal ¶
func (m *IPOrDomain) XXX_Unmarshal(b []byte) error
type IPOrDomain_Domain ¶
type IPOrDomain_Domain struct {
Domain string `protobuf:"bytes,2,opt,name=domain,proto3,oneof"`
}
type IPOrDomain_Ip ¶
type IPOrDomain_Ip struct {
Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3,oneof"`
}
type ListenConfig ¶
type ListenConfig = net.ListenConfig
type Network ¶ added in v0.14.1
type Network int32
func (Network) AsList ¶ added in v1.9.1
func (n Network) AsList() *NetworkList
type NetworkList ¶ added in v0.14.1
type NetworkList struct { Network []Network `protobuf:"varint,1,rep,packed,name=network,proto3,enum=v2ray.core.common.net.Network" json:"network,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
NetworkList is a list of Networks.
func (*NetworkList) Descriptor ¶
func (*NetworkList) Descriptor() ([]byte, []int)
func (NetworkList) Get ¶
func (l NetworkList) Get(idx int) Network
func (*NetworkList) GetNetwork ¶
func (m *NetworkList) GetNetwork() []Network
func (NetworkList) HasNetwork ¶ added in v0.14.1
func (l NetworkList) HasNetwork(network Network) bool
HasNetwork returns true if the given network is in v NetworkList.
func (*NetworkList) ProtoMessage ¶
func (*NetworkList) ProtoMessage()
func (*NetworkList) Reset ¶
func (m *NetworkList) Reset()
func (NetworkList) Size ¶
func (l NetworkList) Size() int
Size returns the number of networks in this network list.
func (*NetworkList) String ¶
func (m *NetworkList) String() string
func (*NetworkList) XXX_DiscardUnknown ¶
func (m *NetworkList) XXX_DiscardUnknown()
func (*NetworkList) XXX_Marshal ¶
func (m *NetworkList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*NetworkList) XXX_Merge ¶
func (m *NetworkList) XXX_Merge(src proto.Message)
func (*NetworkList) XXX_Size ¶
func (m *NetworkList) XXX_Size() int
func (*NetworkList) XXX_Unmarshal ¶
func (m *NetworkList) XXX_Unmarshal(b []byte) error
type PacketConn ¶
type PacketConn = net.PacketConn
type Port ¶ added in v1.1.1
type Port uint16
Port represents a network port in TCP and UDP protocol.
func PortFromBytes ¶ added in v1.1.1
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
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
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
Bytes returns the correspoding bytes of a Port, in big endian order.
func (Port) String ¶ added in v1.1.1
String returns the string presentation of a Port.
type PortRange ¶ added in v0.14.1
type PortRange struct { // The port that this range starts from. From uint32 `protobuf:"varint,1,opt,name=From,proto3" json:"From,omitempty"` // The port that this range ends with (inclusive). To uint32 `protobuf:"varint,2,opt,name=To,proto3" json:"To,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
PortRange represents a range of ports.
func SinglePortRange ¶
SinglePortRange returns a PortRange contains a single port.
func (PortRange) Contains ¶ added in v1.9.1
Contains returns true if the given port is within the range of a PortRange.
func (PortRange) FromPort ¶
FromPort returns the beginning port of this PortRange.
func (PortRange) ToPort ¶
ToPort returns the end port of this PortRange.
func (*PortRange) XXX_Marshal ¶
type TCPListener ¶
type TCPListener = net.TCPListener
type UnixListener ¶
type UnixListener = net.UnixListener