pcapx

package
v1.2.3-sp2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: AGPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PublicGatewayAddress   net.IP
	PublicPreferredAddress net.IP
	PublicInterface        *net.Interface
)
View Source
var (
	Exports = map[string]interface{}{
		"GetStatistics":      getStatistics,
		"InjectRaw":          InjectRaw,
		"InjectIP":           InjectTCPIP,
		"InjectTCP":          InjectTCPIP,
		"InjectHTTPRequest":  InjectHTTPRequest,
		"InjectChaosTraffic": InjectChaosTraffic,
	}
)

Functions

func CreateTCPHandshakePackets

func CreateTCPHandshakePackets(src, dst string, payload []byte) (
	*TCPIPFrame,
	*TCPIPFrame,
	*TCPIPFrame,
	[]*TCPIPFrame,
	*TCPIPFrame,
	error,
)

func GetPublicLinkLayer

func GetPublicLinkLayer(t layers.EthernetType, toServer bool) (*layers.Ethernet, error)

func GetPublicRoute

func GetPublicRoute() (*net.Interface, net.IP, net.IP, error)

func GetPublicToClientLinkLayerIPv4

func GetPublicToClientLinkLayerIPv4() (*layers.Ethernet, error)

func GetPublicToClientLinkLayerIPv6

func GetPublicToClientLinkLayerIPv6() (*layers.Ethernet, error)

func GetPublicToServerLinkLayerIPv4

func GetPublicToServerLinkLayerIPv4() (*layers.Ethernet, error)

func GetPublicToServerLinkLayerIPv6

func GetPublicToServerLinkLayerIPv6() (*layers.Ethernet, error)

func InjectChaosTraffic

func InjectChaosTraffic(t *chaosmaker.ChaosTraffic, opts ...ConfigOption)

func InjectHTTPRequest

func InjectHTTPRequest(raw []byte, opt ...ConfigOption)

func InjectICMPIP

func InjectICMPIP(raw []byte, opt ...ConfigOption)

func InjectRaw

func InjectRaw(raw []byte, opt ...ConfigOption)

func InjectTCPIP

func InjectTCPIP(raw []byte, opt ...ConfigOption)

func InjectTCPIPInstance

func InjectTCPIPInstance(raw *TCPIPFrame, opt ...ConfigOption)

func InjectTCPPayload

func InjectTCPPayload(payload []byte, opt ...ConfigOption)

func InjectUDPIP

func InjectUDPIP(raw []byte, opt ...ConfigOption)

func PacketBuilder added in v1.2.3

func PacketBuilder(opts ...any) ([]byte, error)

func ParseICMPIPv4

func ParseICMPIPv4(raw []byte) (*layers.IPv4, *layers.ICMPv4, gopacket.Payload, error)

func ParseLinkLayer

func ParseLinkLayer(raw []byte) (*layers.Ethernet, *layers.IPv4, *layers.TCP, error)

func ParseSrcNDstAddress

func ParseSrcNDstAddress(src, dst string) (net.IP, net.IP, uint16, uint16, error)

func ParseTCPIPv4

func ParseTCPIPv4(raw []byte) (*layers.IPv4, *layers.TCP, gopacket.Payload, error)

func ParseTCPRaw

func ParseTCPRaw(raw []byte) (*layers.IPv4, *layers.TCP, gopacket.Payload, error)

func ParseUDPIPv4

func ParseUDPIPv4(raw []byte) (*layers.IPv4, *layers.UDP, gopacket.Payload, error)

func RegenerateTCPTraffic

func RegenerateTCPTraffic(raw []byte, localIPAddress string, opt ...ConfigOption)

Types

type ArpLayerBuilderConfig added in v1.2.3

type ArpLayerBuilderConfig struct {
	AddrType        layers.LinkType
	Protocol        layers.EthernetType
	HwAddressSize   uint8
	ProtAddressSize uint8

	// req-1
	// rsp-0
	Operation             uint16
	SourceHwAddress       []byte
	SourceProtocolAddress []byte
	DstHwAddress          []byte
	DstProtocolAddress    []byte
}

func (*ArpLayerBuilderConfig) Create added in v1.2.3

func (a *ArpLayerBuilderConfig) Create() *layers.ARP

type ArpLayerBuilderConfigOption added in v1.2.3

type ArpLayerBuilderConfigOption func(*ArpLayerBuilderConfig)

func ArpLayerBUilderConfigOperation added in v1.2.3

func ArpLayerBUilderConfigOperation(operation uint16) ArpLayerBuilderConfigOption

func ArpLayerBuilderConfigAddrType added in v1.2.3

func ArpLayerBuilderConfigAddrType(addrType layers.LinkType) ArpLayerBuilderConfigOption

func ArpLayerBuilderConfigProtocolTypeRaw added in v1.2.3

func ArpLayerBuilderConfigProtocolTypeRaw(protocol any) ArpLayerBuilderConfigOption

func WithArpLayerBuilderConfigDestination added in v1.2.3

func WithArpLayerBuilderConfigDestination(protocolAddr any, hardwareAddr any) ArpLayerBuilderConfigOption

func WithArpLayerBuilderConfigProtocol added in v1.2.3

func WithArpLayerBuilderConfigProtocol(protocol layers.EthernetType) ArpLayerBuilderConfigOption

func WithArpLayerBuilderConfigRequest added in v1.2.3

func WithArpLayerBuilderConfigRequest() ArpLayerBuilderConfigOption

func WithArpLayerBuilderConfigResponse added in v1.2.3

func WithArpLayerBuilderConfigResponse() ArpLayerBuilderConfigOption

func WithArpLayerBuilderConfigSource added in v1.2.3

func WithArpLayerBuilderConfigSource(protocolAddr any, hardwareAddr any) ArpLayerBuilderConfigOption

type BuilderConfig added in v1.2.3

type BuilderConfig struct {
	Loopback bool
	Payload  []byte
}

type BuilderConfigOption added in v1.2.3

type BuilderConfigOption func(config *BuilderConfig)

func WithLoopback added in v1.2.3

func WithLoopback() BuilderConfigOption

func WithPayload added in v1.2.3

func WithPayload(payload []byte) BuilderConfigOption

type Config

type Config struct {
	Iface       string
	ToServerSet bool
	ToServer    bool
	IsHttps     bool

	TCPLocalAddress  string
	TCPRemoteAddress string
}

type ConfigOption

type ConfigOption func(config *Config)

func WithIface

func WithIface(iface string) ConfigOption

func WithLocalAddress

func WithLocalAddress(addr string) ConfigOption

func WithRemoteAddress

func WithRemoteAddress(addr string) ConfigOption

func WithToClient

func WithToClient() ConfigOption

func WithToServer

func WithToServer() ConfigOption

type EthernetLayerBuilderConfig added in v1.2.3

type EthernetLayerBuilderConfig struct {
	SrcMac       net.HardwareAddr
	DstMac       net.HardwareAddr
	EthernetType layers.EthernetType
}

func (*EthernetLayerBuilderConfig) Create added in v1.2.3

type EthernetLayerBuilderOption added in v1.2.3

type EthernetLayerBuilderOption func(config *EthernetLayerBuilderConfig)

func EthernetLayerBuilderWithDstMac added in v1.2.3

func EthernetLayerBuilderWithDstMac(dstMac net.HardwareAddr) EthernetLayerBuilderOption

func EthernetLayerBuilderWithDstMacStr added in v1.2.3

func EthernetLayerBuilderWithDstMacStr(dstMacStr string) EthernetLayerBuilderOption

func EthernetLayerBuilderWithEthernetType added in v1.2.3

func EthernetLayerBuilderWithEthernetType(i any) EthernetLayerBuilderOption

func EthernetLayerBuilderWithSrcMac added in v1.2.3

func EthernetLayerBuilderWithSrcMac(srcMac net.HardwareAddr) EthernetLayerBuilderOption

func EthernetLayerBuilderWithSrcMacStr added in v1.2.3

func EthernetLayerBuilderWithSrcMacStr(srcMacStr string) EthernetLayerBuilderOption

type IPv4LayerBuilderConfig added in v1.2.3

type IPv4LayerBuilderConfig struct {
	Version    uint8
	IHL        uint8
	TOS        uint8
	Length     uint16
	Id         uint16
	Flags      layers.IPv4Flag
	FragOffset uint16
	TTL        uint8
	Protocol   layers.IPProtocol
	Checksum   uint16
	SrcIP      net.IP
	DstIP      net.IP
	Options    []layers.IPv4Option
}

func (*IPv4LayerBuilderConfig) Create added in v1.2.3

func (i *IPv4LayerBuilderConfig) Create() *layers.IPv4

type IPv4LayerBuilderConfigOption added in v1.2.3

type IPv4LayerBuilderConfigOption func(*IPv4LayerBuilderConfig)

func WithIPv4LayerBuilderConfigDstIP added in v1.2.3

func WithIPv4LayerBuilderConfigDstIP(dstIP any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigFlags added in v1.2.3

func WithIPv4LayerBuilderConfigFlags(flags any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigFragOffset added in v1.2.3

func WithIPv4LayerBuilderConfigFragOffset(fragOffset any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigIHL added in v1.2.3

func WithIPv4LayerBuilderConfigIHL(ihl any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigId added in v1.2.3

func WithIPv4LayerBuilderConfigId(id any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigLength added in v1.2.3

func WithIPv4LayerBuilderConfigLength(length any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigProtocol added in v1.2.3

func WithIPv4LayerBuilderConfigProtocol(protocol any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigSrcIP added in v1.2.3

func WithIPv4LayerBuilderConfigSrcIP(srcIP any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigTOS added in v1.2.3

func WithIPv4LayerBuilderConfigTOS(tos any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigTTL added in v1.2.3

func WithIPv4LayerBuilderConfigTTL(ttl any) IPv4LayerBuilderConfigOption

func WithIPv4LayerBuilderConfigVersion added in v1.2.3

func WithIPv4LayerBuilderConfigVersion(version any) IPv4LayerBuilderConfigOption

type Statistics

type Statistics struct {
	LinkLayerStatistics           map[string]int64
	NetworkLayerStatistics        map[string]int64
	TransportationLayerStatistics map[string]int64
	ICMPStatistics                map[string]int64
}

func GetGlobalStatistics

func GetGlobalStatistics() *Statistics

func NewStatistics

func NewStatistics() *Statistics

func (*Statistics) AddICMPStatistics

func (s *Statistics) AddICMPStatistics(name string)

func (*Statistics) AddLinkLayerStatistics

func (s *Statistics) AddLinkLayerStatistics(name string)

func (*Statistics) AddNetworkLayerStatistics

func (s *Statistics) AddNetworkLayerStatistics(name string)

func (*Statistics) AddTransportationLayerStatistics

func (s *Statistics) AddTransportationLayerStatistics(name string)

type TCPBuilderConfig added in v1.2.3

type TCPBuilderConfig struct {
	SrcPort    int
	DstPort    int
	Seq        int
	Ack        int
	DataOffset int
	FIN        bool
	SYN        bool
	RST        bool
	PSH        bool
	ACK        bool
	URG        bool
	ECE        bool
	CWR        bool
	NS         bool
	Window     int
	Checksum   int
	Urgent     int
	Options    []layers.TCPOption
	Padding    []byte
}

func (*TCPBuilderConfig) Create added in v1.2.3

func (t *TCPBuilderConfig) Create() *layers.TCP

type TCPBuilderConfigOption added in v1.2.3

type TCPBuilderConfigOption func(config *TCPBuilderConfig)

func TCPBuilderConfigWithACK added in v1.2.3

func TCPBuilderConfigWithACK(ack bool) TCPBuilderConfigOption

func TCPBuilderConfigWithAck added in v1.2.3

func TCPBuilderConfigWithAck(ack int) TCPBuilderConfigOption

func TCPBuilderConfigWithCWR added in v1.2.3

func TCPBuilderConfigWithCWR(cwr bool) TCPBuilderConfigOption

func TCPBuilderConfigWithChecksum added in v1.2.3

func TCPBuilderConfigWithChecksum(checksum int) TCPBuilderConfigOption

func TCPBuilderConfigWithDataOffset added in v1.2.3

func TCPBuilderConfigWithDataOffset(dataOffset int) TCPBuilderConfigOption

func TCPBuilderConfigWithDstPort added in v1.2.3

func TCPBuilderConfigWithDstPort(dstPort int) TCPBuilderConfigOption

func TCPBuilderConfigWithECE added in v1.2.3

func TCPBuilderConfigWithECE(ece bool) TCPBuilderConfigOption

func TCPBuilderConfigWithFIN added in v1.2.3

func TCPBuilderConfigWithFIN(fin bool) TCPBuilderConfigOption

func TCPBuilderConfigWithMSS added in v1.2.3

func TCPBuilderConfigWithMSS(mss any) TCPBuilderConfigOption

func TCPBuilderConfigWithNS added in v1.2.3

func TCPBuilderConfigWithNS(ns bool) TCPBuilderConfigOption

func TCPBuilderConfigWithOptions added in v1.2.3

func TCPBuilderConfigWithOptions(options ...layers.TCPOption) TCPBuilderConfigOption

func TCPBuilderConfigWithPSH added in v1.2.3

func TCPBuilderConfigWithPSH(psh bool) TCPBuilderConfigOption

func TCPBuilderConfigWithPadding added in v1.2.3

func TCPBuilderConfigWithPadding(padding []byte) TCPBuilderConfigOption

func TCPBuilderConfigWithRST added in v1.2.3

func TCPBuilderConfigWithRST(rst bool) TCPBuilderConfigOption

func TCPBuilderConfigWithSACKPermitted added in v1.2.3

func TCPBuilderConfigWithSACKPermitted(i int) TCPBuilderConfigOption

func TCPBuilderConfigWithSYN added in v1.2.3

func TCPBuilderConfigWithSYN(syn bool) TCPBuilderConfigOption

func TCPBuilderConfigWithSeq added in v1.2.3

func TCPBuilderConfigWithSeq(seq int) TCPBuilderConfigOption

func TCPBuilderConfigWithSrcPort added in v1.2.3

func TCPBuilderConfigWithSrcPort(srcPort int) TCPBuilderConfigOption

func TCPBuilderConfigWithTimestampNow added in v1.2.3

func TCPBuilderConfigWithTimestampNow(before any) TCPBuilderConfigOption

func TCPBuilderConfigWithTimestamps added in v1.2.3

func TCPBuilderConfigWithTimestamps(now, before any) TCPBuilderConfigOption

func TCPBuilderConfigWithURG added in v1.2.3

func TCPBuilderConfigWithURG(urg bool) TCPBuilderConfigOption

func TCPBuilderConfigWithUrgent added in v1.2.3

func TCPBuilderConfigWithUrgent(urgent int) TCPBuilderConfigOption

func TCPBuilderConfigWithWindow added in v1.2.3

func TCPBuilderConfigWithWindow(window int) TCPBuilderConfigOption

func TCPBuilderConfigWithWindowScale added in v1.2.3

func TCPBuilderConfigWithWindowScale(i int) TCPBuilderConfigOption

type TCPIPFrame

type TCPIPFrame struct {
	ToServer bool
	IP       *layers.IPv4
	TCP      *layers.TCP
}

Jump to

Keyboard shortcuts

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