core: v2ray.com/core/common/net Index | Files

package net

import "v2ray.com/core/common/net"

Package net is a drop-in replacement to Golang's net package, with some more functionalities.

Index

Package Files

address.go address.pb.go connection.go destination.go destination.pb.go errors.generated.go net.go network.go network.pb.go port.go port.pb.go system.go

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
const 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})
)
var CIDRMask = net.CIDRMask
var Dial = net.Dial
var DialTCP = net.DialTCP

DialTCP is an alias of net.DialTCP.

var DialUDP = net.DialUDP
var DialUnix = net.DialUnix
var FileConn = net.FileConn
var Listen = net.Listen
var ListenTCP = net.ListenTCP
var ListenUDP = net.ListenUDP
var ListenUnix = net.ListenUnix
var LookupIP = net.LookupIP
var Network_name = map[int32]string{
    0:  "Unknown",
    1:  "RawTCP",
    2:  "TCP",
    3:  "UDP",
}
var Network_value = map[string]int32{
    "Unknown": 0,
    "RawTCP":  1,
    "TCP":     2,
    "UDP":     3,
}
var ParseIP = net.ParseIP

ParseIP is an alias of net.ParseIP

var ResolveUDPAddr = net.ResolveUDPAddr
var ResolveUnixAddr = net.ResolveUnixAddr
var SplitHostPort = net.SplitHostPort

func HasNetwork Uses

func HasNetwork(list []Network, network Network) bool

HasNetwork returns true if the network list has a certain network.

func NewConnection Uses

func NewConnection(opts ...ConnectionOption) net.Conn

type Addr Uses

type Addr = net.Addr

type AddrError Uses

type AddrError = net.AddrError

type Address Uses

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 Uses

func DomainAddress(domain string) Address

DomainAddress creates an Address with given domain.

func IPAddress Uses

func IPAddress(ip []byte) Address

IPAddress creates an Address with given IP.

func ParseAddress Uses

func ParseAddress(addr string) Address

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.

type AddressFamily Uses

type AddressFamily byte

AddressFamily is the type of address.

func (AddressFamily) IsDomain Uses

func (af AddressFamily) IsDomain() bool

IsDomain returns true if current AddressFamily is Domain.

func (AddressFamily) IsIP Uses

func (af AddressFamily) IsIP() bool

IsIP returns true if current AddressFamily is IPv6 or IPv4.

func (AddressFamily) IsIPv4 Uses

func (af AddressFamily) IsIPv4() bool

IsIPv4 returns true if current AddressFamily is IPv4.

func (AddressFamily) IsIPv6 Uses

func (af AddressFamily) IsIPv6() bool

IsIPv6 returns true if current AddressFamily is IPv6.

type Conn Uses

type Conn = net.Conn

type ConnectionOption Uses

type ConnectionOption func(*connection)

func ConnectionInput Uses

func ConnectionInput(writer io.Writer) ConnectionOption

func ConnectionInputMulti Uses

func ConnectionInputMulti(writer buf.Writer) ConnectionOption

func ConnectionLocalAddr Uses

func ConnectionLocalAddr(a net.Addr) ConnectionOption

func ConnectionOnClose Uses

func ConnectionOnClose(n io.Closer) ConnectionOption

func ConnectionOutput Uses

func ConnectionOutput(reader io.Reader) ConnectionOption

func ConnectionOutputMulti Uses

func ConnectionOutputMulti(reader buf.Reader) ConnectionOption

func ConnectionOutputMultiUDP Uses

func ConnectionOutputMultiUDP(reader buf.Reader) ConnectionOption

func ConnectionRemoteAddr Uses

func ConnectionRemoteAddr(a net.Addr) ConnectionOption

type Destination Uses

type Destination struct {
    Address Address
    Port    Port
    Network Network
}

Destination represents a network destination including address and protocol (tcp / udp).

func DestinationFromAddr Uses

func DestinationFromAddr(addr net.Addr) Destination

DestinationFromAddr generates a Destination from a net address.

func ParseDestination Uses

func ParseDestination(dest string) (Destination, error)

ParseDestination converts a destination from its string presentation.

func TCPDestination Uses

func TCPDestination(address Address, port Port) Destination

TCPDestination creates a TCP destination with given address

func UDPDestination Uses

func UDPDestination(address Address, port Port) Destination

UDPDestination creates a UDP destination with given address

func (Destination) IsValid Uses

func (d Destination) IsValid() bool

IsValid returns true if this Destination is valid.

func (Destination) NetAddr Uses

func (d Destination) NetAddr() string

NetAddr returns the network address in this Destination in string form.

func (Destination) String Uses

func (d Destination) String() string

String returns the strings form of this Destination.

type Dialer Uses

type Dialer = net.Dialer

type Endpoint Uses

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 Uses

func (p *Endpoint) AsDestination() Destination

AsDestination converts current Endpoint into Destination.

func (*Endpoint) Descriptor Uses

func (*Endpoint) Descriptor() ([]byte, []int)

func (*Endpoint) GetAddress Uses

func (m *Endpoint) GetAddress() *IPOrDomain

func (*Endpoint) GetNetwork Uses

func (m *Endpoint) GetNetwork() Network

func (*Endpoint) GetPort Uses

func (m *Endpoint) GetPort() uint32

func (*Endpoint) ProtoMessage Uses

func (*Endpoint) ProtoMessage()

func (*Endpoint) Reset Uses

func (m *Endpoint) Reset()

func (*Endpoint) String Uses

func (m *Endpoint) String() string

func (*Endpoint) XXX_DiscardUnknown Uses

func (m *Endpoint) XXX_DiscardUnknown()

func (*Endpoint) XXX_Marshal Uses

func (m *Endpoint) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Endpoint) XXX_Merge Uses

func (m *Endpoint) XXX_Merge(src proto.Message)

func (*Endpoint) XXX_Size Uses

func (m *Endpoint) XXX_Size() int

func (*Endpoint) XXX_Unmarshal Uses

func (m *Endpoint) XXX_Unmarshal(b []byte) error

type Error Uses

type Error = net.Error

type IP Uses

type IP = net.IP

IP is an alias for net.IP.

type IPMask Uses

type IPMask = net.IPMask

type IPNet Uses

type IPNet = net.IPNet

type IPOrDomain Uses

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 Uses

func NewIPOrDomain(addr Address) *IPOrDomain

NewIPOrDomain translates Address to IPOrDomain

func (*IPOrDomain) AsAddress Uses

func (d *IPOrDomain) AsAddress() Address

AsAddress translates IPOrDomain to Address.

func (*IPOrDomain) Descriptor Uses

func (*IPOrDomain) Descriptor() ([]byte, []int)

func (*IPOrDomain) GetAddress Uses

func (m *IPOrDomain) GetAddress() isIPOrDomain_Address

func (*IPOrDomain) GetDomain Uses

func (m *IPOrDomain) GetDomain() string

func (*IPOrDomain) GetIp Uses

func (m *IPOrDomain) GetIp() []byte

func (*IPOrDomain) ProtoMessage Uses

func (*IPOrDomain) ProtoMessage()

func (*IPOrDomain) Reset Uses

func (m *IPOrDomain) Reset()

func (*IPOrDomain) String Uses

func (m *IPOrDomain) String() string

func (*IPOrDomain) XXX_DiscardUnknown Uses

func (m *IPOrDomain) XXX_DiscardUnknown()

func (*IPOrDomain) XXX_Marshal Uses

func (m *IPOrDomain) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*IPOrDomain) XXX_Merge Uses

func (m *IPOrDomain) XXX_Merge(src proto.Message)

func (*IPOrDomain) XXX_OneofWrappers Uses

func (*IPOrDomain) XXX_OneofWrappers() []interface{}

XXX_OneofWrappers is for the internal use of the proto package.

func (*IPOrDomain) XXX_Size Uses

func (m *IPOrDomain) XXX_Size() int

func (*IPOrDomain) XXX_Unmarshal Uses

func (m *IPOrDomain) XXX_Unmarshal(b []byte) error

type IPOrDomain_Domain Uses

type IPOrDomain_Domain struct {
    Domain string `protobuf:"bytes,2,opt,name=domain,proto3,oneof"`
}

type IPOrDomain_Ip Uses

type IPOrDomain_Ip struct {
    Ip []byte `protobuf:"bytes,1,opt,name=ip,proto3,oneof"`
}

type ListenConfig Uses

type ListenConfig = net.ListenConfig

type Listener Uses

type Listener = net.Listener

type MemoryPortList Uses

type MemoryPortList []MemoryPortRange

func PortListFromProto Uses

func PortListFromProto(l *PortList) MemoryPortList

func (MemoryPortList) Contains Uses

func (mpl MemoryPortList) Contains(port Port) bool

type MemoryPortRange Uses

type MemoryPortRange struct {
    From Port
    To   Port
}

func (MemoryPortRange) Contains Uses

func (r MemoryPortRange) Contains(port Port) bool

type Network Uses

type Network int32
const (
    Network_Unknown Network = 0
    Network_RawTCP  Network = 1 // Deprecated: Do not use.
    Network_TCP     Network = 2
    Network_UDP     Network = 3
)

func (Network) EnumDescriptor Uses

func (Network) EnumDescriptor() ([]byte, []int)

func (Network) String Uses

func (x Network) String() string

func (Network) SystemString Uses

func (n Network) SystemString() string

type NetworkList Uses

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 Uses

func (*NetworkList) Descriptor() ([]byte, []int)

func (*NetworkList) GetNetwork Uses

func (m *NetworkList) GetNetwork() []Network

func (*NetworkList) ProtoMessage Uses

func (*NetworkList) ProtoMessage()

func (*NetworkList) Reset Uses

func (m *NetworkList) Reset()

func (*NetworkList) String Uses

func (m *NetworkList) String() string

func (*NetworkList) XXX_DiscardUnknown Uses

func (m *NetworkList) XXX_DiscardUnknown()

func (*NetworkList) XXX_Marshal Uses

func (m *NetworkList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*NetworkList) XXX_Merge Uses

func (m *NetworkList) XXX_Merge(src proto.Message)

func (*NetworkList) XXX_Size Uses

func (m *NetworkList) XXX_Size() int

func (*NetworkList) XXX_Unmarshal Uses

func (m *NetworkList) XXX_Unmarshal(b []byte) error

type PacketConn Uses

type PacketConn = net.PacketConn

type Port Uses

type Port uint16

Port represents a network port in TCP and UDP protocol.

func PortFromBytes Uses

func PortFromBytes(port []byte) Port

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 Uses

func PortFromInt(val uint32) (Port, error)

PortFromInt converts an integer to a Port. @error when the integer is not positive or larger then 65535

func PortFromString Uses

func PortFromString(s string) (Port, error)

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) String Uses

func (p Port) String() string

String returns the string presentation of a Port.

func (Port) Value Uses

func (p Port) Value() uint16

Value return the correspoding uint16 value of a Port.

type PortList Uses

type PortList struct {
    Range                []*PortRange `protobuf:"bytes,1,rep,name=range,proto3" json:"range,omitempty"`
    XXX_NoUnkeyedLiteral struct{}     `json:"-"`
    XXX_unrecognized     []byte       `json:"-"`
    XXX_sizecache        int32        `json:"-"`
}

PortList is a list of ports.

func (*PortList) Descriptor Uses

func (*PortList) Descriptor() ([]byte, []int)

func (*PortList) GetRange Uses

func (m *PortList) GetRange() []*PortRange

func (*PortList) ProtoMessage Uses

func (*PortList) ProtoMessage()

func (*PortList) Reset Uses

func (m *PortList) Reset()

func (*PortList) String Uses

func (m *PortList) String() string

func (*PortList) XXX_DiscardUnknown Uses

func (m *PortList) XXX_DiscardUnknown()

func (*PortList) XXX_Marshal Uses

func (m *PortList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PortList) XXX_Merge Uses

func (m *PortList) XXX_Merge(src proto.Message)

func (*PortList) XXX_Size Uses

func (m *PortList) XXX_Size() int

func (*PortList) XXX_Unmarshal Uses

func (m *PortList) XXX_Unmarshal(b []byte) error

type PortRange Uses

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 Uses

func SinglePortRange(p Port) *PortRange

SinglePortRange returns a PortRange contains a single port.

func (PortRange) Contains Uses

func (p PortRange) Contains(port Port) bool

Contains returns true if the given port is within the range of a PortRange.

func (*PortRange) Descriptor Uses

func (*PortRange) Descriptor() ([]byte, []int)

func (PortRange) FromPort Uses

func (p PortRange) FromPort() Port

FromPort returns the beginning port of this PortRange.

func (*PortRange) GetFrom Uses

func (m *PortRange) GetFrom() uint32

func (*PortRange) GetTo Uses

func (m *PortRange) GetTo() uint32

func (*PortRange) ProtoMessage Uses

func (*PortRange) ProtoMessage()

func (*PortRange) Reset Uses

func (m *PortRange) Reset()

func (*PortRange) String Uses

func (m *PortRange) String() string

func (PortRange) ToPort Uses

func (p PortRange) ToPort() Port

ToPort returns the end port of this PortRange.

func (*PortRange) XXX_DiscardUnknown Uses

func (m *PortRange) XXX_DiscardUnknown()

func (*PortRange) XXX_Marshal Uses

func (m *PortRange) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*PortRange) XXX_Merge Uses

func (m *PortRange) XXX_Merge(src proto.Message)

func (*PortRange) XXX_Size Uses

func (m *PortRange) XXX_Size() int

func (*PortRange) XXX_Unmarshal Uses

func (m *PortRange) XXX_Unmarshal(b []byte) error

type Resolver Uses

type Resolver = net.Resolver

type TCPAddr Uses

type TCPAddr = net.TCPAddr

type TCPConn Uses

type TCPConn = net.TCPConn

type TCPListener Uses

type TCPListener = net.TCPListener

type UDPAddr Uses

type UDPAddr = net.UDPAddr

type UDPConn Uses

type UDPConn = net.UDPConn

type UnixAddr Uses

type UnixAddr = net.UnixAddr

type UnixConn Uses

type UnixConn = net.UnixConn

type UnixListener Uses

type UnixListener = net.UnixListener

Package net imports 14 packages (graph) and is imported by 172 packages. Updated 2019-02-25. Refresh now. Tools for package owners.