engine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BROADCAST_MAC_ADDR = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
)

Functions

func ParseIpAddr

func ParseIpAddr(ipAddrStr string) ([]byte, error)

func ParseMacAddr

func ParseMacAddr(macAddrStr string) ([]byte, error)

Types

type Config

type Config struct {
	DebugLog        bool           // 调试日志
	NetIfConfigList []*NetIfConfig // 网卡列表
}

type Engine

type Engine struct {
	DebugLog bool
	Stop     bool
	NetIfMap map[string]*NetIf
}

func InitEngine

func InitEngine(config *Config) (*Engine, error)

func (*Engine) GetNetIf

func (e *Engine) GetNetIf(name string) *NetIf

func (*Engine) RunEngine

func (e *Engine) RunEngine()

func (*Engine) StopEngine

func (e *Engine) StopEngine()

type NetIf

type NetIf struct {
	Name          string
	MacAddr       []byte
	IpAddr        []byte
	NetworkMask   []byte
	GatewayIpAddr []byte
	EthRxChan     chan []byte
	EthTxChan     chan []byte
	Engine        *Engine
	// arp缓存表 key:ip value:mac
	ArpCacheTable     map[uint32]uint64
	ArpCacheTableLock sync.RWMutex
	HandleUdp         func(udpPayload []byte, udpSrcPort uint16, udpDstPort uint16, ipv4SrcAddr []byte)
}

func (*NetIf) ConvMacAddrToUint64

func (i *NetIf) ConvMacAddrToUint64(macAddr []byte) (macAddrUint64 uint64)

func (*NetIf) ConvUint64ToMacAddr

func (i *NetIf) ConvUint64ToMacAddr(macAddrUint64 uint64) (macAddr []byte)

func (*NetIf) GetArpCache

func (i *NetIf) GetArpCache(ipAddr []byte) (macAddr []byte)

func (*NetIf) HandleArp

func (i *NetIf) HandleArp(ethPayload []byte, ethSrcMac []byte)

func (*NetIf) NetworkStateCheck

func (i *NetIf) NetworkStateCheck()

func (*NetIf) PacketHandle

func (i *NetIf) PacketHandle()

func (*NetIf) RxIcmp

func (i *NetIf) RxIcmp(ipv4Payload []byte, ipv4SrcAddr []byte)

func (*NetIf) RxIpv4

func (i *NetIf) RxIpv4(ethPayload []byte)

func (*NetIf) RxTcp

func (i *NetIf) RxTcp()

func (*NetIf) RxUdp

func (i *NetIf) RxUdp(ipv4Payload []byte, ipv4SrcAddr []byte)

func (*NetIf) SetArpCache

func (i *NetIf) SetArpCache(ipAddr []byte, macAddr []byte)

func (*NetIf) TxIcmp

func (i *NetIf) TxIcmp(icmpPayload []byte, seq uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxIpv4

func (i *NetIf) TxIpv4(ipv4Payload []byte, ipv4HeadProto uint8, ipv4DstAddr []byte) []byte

func (*NetIf) TxTcpAck

func (i *NetIf) TxTcpAck(tcpSrcPort uint16, tcpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxTcpSyn

func (i *NetIf) TxTcpSyn(tcpSrcPort uint16, tcpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxTcpSynAck

func (i *NetIf) TxTcpSynAck(tcpSrcPort uint16, tcpDstPort uint16, ipv4DstAddr []byte) []byte

func (*NetIf) TxUdp

func (i *NetIf) TxUdp(udpPayload []byte, udpSrcPort uint16, udpDstPort uint16, ipv4DstAddr []byte) []byte

type NetIfConfig

type NetIfConfig struct {
	Name          string      // 网卡名
	MacAddr       string      // mac地址
	IpAddr        string      // ip地址
	NetworkMask   string      // 子网掩码
	GatewayIpAddr string      // 网关ip地址
	EthRxChan     chan []byte // 物理层接收管道
	EthTxChan     chan []byte // 物理层发送管道
}

Jump to

Keyboard shortcuts

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