xxnet

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyErr = fmt.Errorf("empty routeInfo result")
)
View Source
var (
	EmptyInterface = []*net.Interface{}
)
View Source
var (
	ErrLog io.Writer
)
View Source
var (
	InvlidHostError = fmt.Errorf("invlid host")
)

Functions

func CheckIP

func CheckIP(ip []byte) bool

func CheckPort

func CheckPort(port int) bool

func GetLocalAddress added in v0.0.2

func GetLocalAddress(iterfaceName string) (addr *net.IP, err error)

func GetPid added in v0.0.6

func GetPid(addr int64) (pid string, err error)

func GetSocketId added in v0.0.6

func GetSocketId(port string) (SocketId string, err error)

func Icmp added in v0.0.2

func Icmp(addr net.IPAddr, opts ...ss)

func ListenTcp added in v0.0.10

func ListenTcp(host string, portRange string) (net.Listener, error)

func ListenTcpWithAll added in v0.0.10

func ListenTcpWithAll(portRange string) (net.Listener, error)

like xxnet.ListenTcp("0.0.0.0",portRange)

func ListenTcpWithLoop added in v0.0.10

func ListenTcpWithLoop(portRange string) (net.Listener, error)

like xxnet.ListenTcp("127.0.0.1",portRange)

func ParseHttpHeadString added in v0.0.2

func ParseHttpHeadString(text string) map[string][]string

func ParseIfaceAddrs added in v0.0.8

func ParseIfaceAddrs(addr []net.Addr) (ipv4 *net.IPNet, ipv6 *net.IPNet, err error)

转换 net.Interface 系列api返回的 的接口下的ip列表为对应的网络ip结构体

func ParseIfaceAddrsOfIpv4 added in v0.0.8

func ParseIfaceAddrsOfIpv4(addr []net.Addr) (ipv4 *net.IPNet, err error)

func ParseIfaceAddrsOfIpv6 added in v0.0.8

func ParseIfaceAddrsOfIpv6(addr []net.Addr) (ipv6 *net.IPNet, err error)

func ParsePort added in v0.0.10

func ParsePort(ports string) (uint16, error)

func ParsePortRange added in v0.0.10

func ParsePortRange(portRange string) (portsFunc portsFunc, err error)

解析一个端口范围

func PasrseTcpAddr

func PasrseTcpAddr(addr *net.TCPAddr) (ipv4 []byte, port int, err error)

func RouteInterfaces added in v0.0.8

func RouteInterfaces() ([]*net.Interface, error)

获取当前本机网卡(包含物理网卡,虚拟网桥)具有静态路由的ip地址列表,

Types

type Flag added in v0.0.8

type Flag uint16
const (
	Flag_Up      Flag = 1 << iota // U (route is up)
	Flag_Host                     // H (target is a host)
	Flag_Gateway                  // G (use gateway)
	Flag_R                        // R (reinstate route for dynamic routing)
	Flag_D                        // D (dynamically installed by daemon or redirect)
	Flag_M                        // M (modified from routing daemon or redirect)
	Flag_A                        // A (installed by addrconf)
	Flag_Cache                    // C (cache entry)
	Flag_Reject                   // !  (reject route)
)

func (Flag) Has added in v0.0.8

func (f Flag) Has(o Flag) bool

type HostAddr added in v0.0.2

type HostAddr struct {
	Hostip string
	Port   string
}

func ParseHostAddr added in v0.0.2

func ParseHostAddr(ipport string) (hostaddr HostAddr, err error)

type IcmpOptions added in v0.0.2

type IcmpOptions struct {
	// contains filtered or unexported fields
}

func (*IcmpOptions) WithTimeout added in v0.0.2

func (i *IcmpOptions) WithTimeout(d time.Duration) ss

type IcmpRequest added in v0.0.2

type IcmpRequest struct {
	Type        byte
	Code        byte
	Checksum    uint16
	Identifier  uint16
	SequenceNum uint16
}

type IcmpResp added in v0.0.2

type IcmpResp struct {
}

icmp 响应.

type Iface added in v0.0.2

type Iface struct {
	net.Interface
}

func (Iface) GetIpv4 added in v0.0.2

func (this Iface) GetIpv4() (*net.IPAddr, error)

type RouteInfo added in v0.0.8

type RouteInfo struct {
	Destination net.IP // 目标 The destination network or destination host.
	Gateway     net.IP // 网关 The gateway address or '*' if none set
	Genmask     net.IP // 子网掩码 The  netmask  for  the destination net; '255.255.255.255' for a host destination and '0.0.0.0' for the default route.

	Flags        Flag  // 标志 Possible flags see Flag
	Metric       int32 // 跃点 The 'distance' to the target (usually counted in hops).
	Ref          int16 // 引用 Number of references to this route. (Not used in the Linux kernel.)
	Use          int16 // 使用 Count of lookups for the route.  Depending on the use of -F and -C this will be  either  routecache misses (-F) or hits (-C).
	NetInterface net.Interface
	Iface        string // 接口 Interface to which packets for this route will be sent.
	MSS          int16  // Default maximum segment size for TCP connections over this route.
	Window       int16  // Default window size for TCP connections over this route.
	Irtt         int16  // Initial  RTT  (Round  Trip  Time).  The  kernel uses this to guess about the best TCP protocolparameters without waiting on (possibly slow) answers.
	// contains filtered or unexported fields
}

func FlushRouteInfoCache added in v0.0.8

func FlushRouteInfoCache() ([]RouteInfo, error)

todo 得到在系统网卡状态变化的事件,自动刷新

func GetCacheRouteInfo added in v0.0.8

func GetCacheRouteInfo() ([]RouteInfo, error)

优先获取当前缓存的.路由结果集, 如果结果集为空,则返回 错误

func GetDefalutRouteInfo added in v0.0.8

func GetDefalutRouteInfo() (ri RouteInfo, err error)

获取当前默认路由所在的网络ip,如果有多个,则按照 Metric值,优先获取值小的

func MustGetDefalutRouteInfo added in v0.0.8

func MustGetDefalutRouteInfo() RouteInfo

func ObtainRouteInfo added in v0.0.8

func ObtainRouteInfo() ([]RouteInfo, error)

func (RouteInfo) GetIfaceIpv4 added in v0.0.8

func (r RouteInfo) GetIfaceIpv4() (*net.IPNet, error)

获取当前路由信息的本地网卡地址

func (RouteInfo) IsDefaultRoute added in v0.0.8

func (r RouteInfo) IsDefaultRoute() bool

默认路由就是 目的网络地址为 0.0.0.0, 且flag设置为gateway

func (RouteInfo) MustGetIfaceIpv4 added in v0.0.8

func (r RouteInfo) MustGetIfaceIpv4() *net.IPNet

type RouteInfos added in v0.0.8

type RouteInfos []RouteInfo

func GetDefalutRouteInfos added in v0.0.8

func GetDefalutRouteInfos() (ri RouteInfos, err error)

获取当前默认路由所在的网络接口列表,默认路由就是 目的网络地址为 0.0.0.0, 且flag设置为gateway

func (RouteInfos) Len added in v0.0.8

func (r RouteInfos) Len() int

func (RouteInfos) Less added in v0.0.8

func (r RouteInfos) Less(i, j int) bool

func (RouteInfos) Swap added in v0.0.8

func (r RouteInfos) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL