bridgeC

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConnTypeIp   = 0 // ip packet
	ConnTypeIcmp     // icmp packet
	ConnTypeTcp      // tcp packet
	ConnTypeUdp      // udp packet
)
View Source
const (
	ACT_IP_RECEIVE  = 0 // 收到ip包
	ACT_TCP_CONNECT     // 新的TCP连接
	ACT_TCP_SEND        // tcp发送
	ACT_TCP_RECEIVE     // 收到tcp包
	ACT_TCP_CLOSE       // 关闭
	ACT_UDP_SEND        // udp发送
	ACT_UDP_RECEIVE     // 收到udp包
	ACT_UDP_CLOSE       // 关闭
)
View Source
const (
	PacketNodeSize     = 1500                  // 每个数据包大小
	PacketNodeCount    = 16                    // 数据包个数
	PacketBufChanCount = PacketNodeCount * 100 // 接近 2.5MB 缓存
)

Variables

This section is empty.

Functions

func GetLocalIp

func GetLocalIp() string

func LogGO

func LogGO(level C.int, logString *C.char)

func OneConnectGO

func OneConnectGO(id C.uint64, connType C.int, localIp *C.char, localPort C.uint16,
	remoteIp *C.char, remotePort C.uint16) C.int

func ReceivePacketsGO

func ReceivePacketsGO(id C.uint64, remoteIp *C.char, remotePort C.uint16,
	connType C.int, packetAct C.int,
	packet *C.char, packetSize C.uint32) C.int

func RunDriver

func RunDriver(localTcpProxyAddr, localUdpProxyAddr, dnsServer string, processNameArray []string, proxy Proxy) bool

func RunTun

func RunTun(address, dnsServer, routeTxt string, proxy Proxy) bool

func SendToAdapter

func SendToAdapter(id uint64, isFromRemoteBind int, remoteIp string, remotePort uint16,
	connType int, packet []byte) int

*

  • SendToAdapter 发送数据到底层. *

  • @param id 唯一ID用于区分连接,如果packetType=ConnTypeIp,则忽略

  • @param isFromRemoteBind 是否来自服务端bind模式

  • @param remoteIp 远端IP

  • @param remotePort 远端Port

  • @param connType 数据包类型 ip、icmp、tcp、udp: ConnTypeIp, // ip packet ConnTypeIcmp, // icmp packet ConnTypeTcp, // tcp packet ConnTypeUdp // udp packet

  • @param packet Pointer to receive data. *

  • 返回值 成功>=0 , 失败<0

*

func TunClose

func TunClose(id uint64) int

*

  • TunClose 关闭底层连接. *
  • @param id 唯一ID用于区分连接 *
  • 返回值 成功>=0 , 失败<0

*

func TunConnectionStatusGO

func TunConnectionStatusGO(id C.uint64) C.int

func TunPrintMemInfo

func TunPrintMemInfo()

*

  • TunPrintMemInfo 打印内存信息

*

Types

type AdapterConnMgr

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

func AdapterConnMgrInstance

func AdapterConnMgrInstance() *AdapterConnMgr

func (*AdapterConnMgr) AcceptConnection

func (cm *AdapterConnMgr) AcceptConnection(id uint64, connType int,
	localAddr string, remoteAddr string) bool

func (*AdapterConnMgr) CloseConnection

func (cm *AdapterConnMgr) CloseConnection(id uint64) int

关闭连接

func (*AdapterConnMgr) ConnectionStatus

func (cm *AdapterConnMgr) ConnectionStatus(id uint64) int

func (*AdapterConnMgr) ReceivePackets

func (cm *AdapterConnMgr) ReceivePackets(id uint64, packet []byte, dstAddr string) int

数据包

type LwipConn

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

func NewConn

func NewConn(connType int, connId uint64, localAddr string, remoteAddr string) *LwipConn

func (*LwipConn) Close

func (c *LwipConn) Close() error

func (*LwipConn) LocalAddr

func (c *LwipConn) LocalAddr() net.Addr

func (*LwipConn) PushPacket

func (c *LwipConn) PushPacket(packet []byte, dstAddr string) int

func (*LwipConn) Read

func (c *LwipConn) Read(b []byte) (n int, err error)

func (*LwipConn) ReadFromBind

func (c *LwipConn) ReadFromBind(b []byte) (n int, addr net.Addr, err error)

目前只能是udp FIXME 目前受限于虚拟网卡无法实现来自本地网卡同一个本地地址的udp,不一样的目标地址的数据包 能够关联上,所有目前只适用nat打洞

func (*LwipConn) RemoteAddr

func (c *LwipConn) RemoteAddr() net.Addr

func (*LwipConn) SetDeadline

func (c *LwipConn) SetDeadline(t time.Time) error

func (*LwipConn) SetReadDeadline

func (c *LwipConn) SetReadDeadline(t time.Time) error

func (*LwipConn) SetWriteDeadline

func (c *LwipConn) SetWriteDeadline(t time.Time) error

func (*LwipConn) Status

func (c *LwipConn) Status() int

获取 连接状态 返回0表示正常 返回1表示缓存满了

func (*LwipConn) Write

func (c *LwipConn) Write(b []byte) (n int, err error)

func (*LwipConn) WriteToFromBind

func (c *LwipConn) WriteToFromBind(b []byte, from net.Addr) (n int, err error)

type Packet

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

type Proxy

type Proxy interface {
	AcceptTcp(src net.Conn, from net.Addr, to net.Addr) bool
	AcceptUdp(src net.Conn, from net.Addr, to net.Addr) bool
	AcceptIp(src net.Conn, from net.Addr, to net.Addr) bool
	AcceptIcmp(src net.Conn, from net.Addr, to net.Addr) bool
	DnsPair(domain, ip string)
}

type TunReactor

type TunReactor interface {
	// 新连接 udp或者tcp
	AcceptConnection(id uint64, connType int,
		localAddr string, remoteAddr string) bool
	// 数据包
	ReceivePackets(id uint64, packet []byte) int
	// 关闭连接
	CloseConnection(id uint64) int
	// 获取连接状态
	ConnectionStatus(id uint64) int
}

Jump to

Keyboard shortcuts

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