Documentation ¶
Overview ¶
Package net contains common network utilities.
Index ¶
- Constants
- Variables
- type Address
- type AddressFamily
- type Destination
- type Endpoint
- func (v *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
- type IPNet
- type IPOrDomain
- func (v *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 (*IPOrDomain) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, ...)
- type IPOrDomain_Domain
- type IPOrDomain_Ip
- type Network
- type NetworkList
- func (*NetworkList) Descriptor() ([]byte, []int)
- func (v NetworkList) Get(idx int) Network
- func (m *NetworkList) GetNetwork() []Network
- func (v NetworkList) HasNetwork(network Network) bool
- func (*NetworkList) ProtoMessage()
- func (m *NetworkList) Reset()
- func (v NetworkList) Size() int
- func (m *NetworkList) String() string
- type Port
- type PortRange
- func (v PortRange) Contains(port Port) bool
- func (*PortRange) Descriptor() ([]byte, []int)
- func (v 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 (v PortRange) ToPort() Port
Constants ¶
const ( AddressFamilyIPv4 = AddressFamily(0) AddressFamilyIPv6 = AddressFamily(1) 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}) )
Functions ¶
This section is empty.
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 int
func (AddressFamily) Either ¶ added in v1.24.1
func (v AddressFamily) Either(fs ...AddressFamily) bool
func (AddressFamily) IsDomain ¶ added in v1.24.1
func (v AddressFamily) IsDomain() bool
func (AddressFamily) IsIPv4 ¶ added in v1.24.1
func (v AddressFamily) IsIPv4() bool
func (AddressFamily) IsIPv6 ¶ added in v1.24.1
func (v AddressFamily) IsIPv6() bool
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
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 (v Destination) IsValid() bool
func (Destination) NetAddr ¶ added in v1.9.1
func (v Destination) NetAddr() string
func (Destination) String ¶
func (v Destination) String() string
type Endpoint ¶
type Endpoint struct { Network Network `protobuf:"varint,1,opt,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"` Address *IPOrDomain `protobuf:"bytes,2,opt,name=address" json:"address,omitempty"` Port uint32 `protobuf:"varint,3,opt,name=port" json:"port,omitempty"` }
func (*Endpoint) AsDestination ¶
func (v *Endpoint) AsDestination() Destination
func (*Endpoint) GetAddress ¶
func (m *Endpoint) GetAddress() *IPOrDomain
type IPNet ¶ added in v1.1.1
type IPNet struct {
// contains filtered or unexported fields
}
type IPOrDomain ¶
type IPOrDomain struct { // Types that are valid to be assigned to Address: // *IPOrDomain_Ip // *IPOrDomain_Domain Address isIPOrDomain_Address `protobuf_oneof:"address"` }
func NewIPOrDomain ¶
func NewIPOrDomain(addr Address) *IPOrDomain
func (*IPOrDomain) AsAddress ¶
func (v *IPOrDomain) AsAddress() 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_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.
type IPOrDomain_Domain ¶
type IPOrDomain_Domain struct {
Domain string `protobuf:"bytes,2,opt,name=domain,oneof"`
}
type IPOrDomain_Ip ¶
type IPOrDomain_Ip struct {
Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3,oneof"`
}
type Network ¶ added in v0.14.1
type Network int32
func (Network) AsList ¶ added in v1.9.1
func (v Network) AsList() *NetworkList
type NetworkList ¶ added in v0.14.1
type NetworkList struct {
Network []Network `protobuf:"varint,1,rep,packed,name=network,enum=v2ray.core.common.net.Network" json:"network,omitempty"`
}
func (*NetworkList) Descriptor ¶
func (*NetworkList) Descriptor() ([]byte, []int)
func (NetworkList) Get ¶
func (v NetworkList) Get(idx int) Network
func (*NetworkList) GetNetwork ¶
func (m *NetworkList) GetNetwork() []Network
func (NetworkList) HasNetwork ¶ added in v0.14.1
func (v NetworkList) HasNetwork(network Network) bool
HashNetwork 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 (v NetworkList) Size() int
func (*NetworkList) String ¶
func (m *NetworkList) String() string
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 v Port, in big endian order.
func (Port) String ¶ added in v1.1.1
String returns the string presentation of v Port.
type PortRange ¶ added in v0.14.1
type PortRange struct { From uint32 `protobuf:"varint,1,opt,name=From" json:"From,omitempty"` To uint32 `protobuf:"varint,2,opt,name=To" json:"To,omitempty"` }
PortRange represents a range of ports.
func (PortRange) Contains ¶ added in v1.9.1
Contains returns true if the given port is within the range of v PortRange.