Documentation ¶
Index ¶
- Constants
- Variables
- type EthernetType
- type IPProtocol
- type LinkType
- type PktConn
- func (pktConn *PktConn) Close()
- func (pktConn *PktConn) LocalAddr() *RawPktAddr
- func (pktConn *PktConn) Read(data []byte) (int, error)
- func (pktConn *PktConn) ReadFrom(data []byte, raddr *RawPktAddr) (int, error)
- func (pktConn *PktConn) ReadFromMsg(data []byte) (laddr *RawPktAddr, raddr *RawPktAddr, ioBytes int, err error)
- func (pktConn *PktConn) RemoteAddr() *RawPktAddr
- func (pktConn *PktConn) SetLocalAddr(addr *RawPktAddr) error
- func (pktConn *PktConn) SetPromisc(flag bool) (oldflag bool, err error)
- func (pktConn *PktConn) SetReadTimeOut(val int) int
- func (pktConn *PktConn) SetRemoteAddr(addr *RawPktAddr) error
- func (pktConn *PktConn) SetTimeOut(val int) (int, int)
- func (pktConn *PktConn) SetWriteTimeOut(val int) int
- func (pktConn *PktConn) Write(data []byte) (int, error)
- func (pktConn *PktConn) WriteTo(data []byte, raddr *RawPktAddr) (int, error)
- type RawPktAddr
- type RawPktConn
- func (rawPktConn *RawPktConn) Close()
- func (rawPktConn *RawPktConn) ReadFromAddr(lfaddr *RawPktAddr, rfaddr *RawPktAddr, payload []byte) (laddr *RawPktAddr, raddr *RawPktAddr, ioBytes int, err error)
- func (rawPktConn *RawPktConn) SetPromisc(flag bool) (oldflag bool, err error)
- func (rawPktConn *RawPktConn) SetReadTimeOut(val int) int
- func (rawPktConn *RawPktConn) SetTimeOut(val int) (int, int)
- func (rawPktConn *RawPktConn) SetWriteTimeOut(val int) int
- func (rawPktConn *RawPktConn) WriteToAddr(laddr *RawPktAddr, raddr *RawPktAddr, payload []byte) (int, error)
Constants ¶
const DEFAULT_MTU = 1500
const UDP_HDR_SIZE = 42
Variables ¶
var HwAddrBroadcast net.HardwareAddr
var HwAddrZero net.HardwareAddr
Functions ¶
This section is empty.
Types ¶
type EthernetType ¶
type EthernetType uint16
EthernetType is an enumeration of ethernet type values, and acts as a decoder for any type it supports.
const ( // EthernetTypeLLC is not an actual ethernet type. It is instead a // placeholder we use in Ethernet frames that use the 802.3 standard of // srcmac|dstmac|length|LLC instead of srcmac|dstmac|ethertype. EthernetTypeLLC EthernetType = 0 EthernetTypeIPv4 EthernetType = 0x0800 EthernetTypeARP EthernetType = 0x0806 EthernetTypeIPv6 EthernetType = 0x86DD EthernetTypeCiscoDiscovery EthernetType = 0x2000 EthernetTypeNortelDiscovery EthernetType = 0x01a2 EthernetTypeDot1Q EthernetType = 0x8100 EthernetTypePPPoEDiscovery EthernetType = 0x8863 EthernetTypePPPoESession EthernetType = 0x8864 EthernetTypeMPLSUnicast EthernetType = 0x8847 EthernetTypeMPLSMulticast EthernetType = 0x8848 EthernetTypeEAPOL EthernetType = 0x888e EthernetTypeLinkLayerDiscovery EthernetType = 0x88cc EthernetTypeEthernetCTP EthernetType = 0x9000 )
type IPProtocol ¶
type IPProtocol uint8
IPProtocol is an enumeration of IP protocol values, and acts as a decoder for any type it supports.
const ( IPProtocolIPv6HopByHop IPProtocol = 0 IPProtocolICMPv4 IPProtocol = 1 IPProtocolIGMP IPProtocol = 2 IPProtocolTCP IPProtocol = 6 IPProtocolUDP IPProtocol = 17 IPProtocolRUDP IPProtocol = 27 IPProtocolIPv6 IPProtocol = 41 IPProtocolIPv6Routing IPProtocol = 43 IPProtocolIPv6Fragment IPProtocol = 44 IPProtocolGRE IPProtocol = 47 IPProtocolESP IPProtocol = 50 IPProtocolAH IPProtocol = 51 IPProtocolICMPv6 IPProtocol = 58 IPProtocolNoNextHeader IPProtocol = 59 IPProtocolIPIP IPProtocol = 94 IPProtocolEtherIP IPProtocol = 97 IPProtocolSCTP IPProtocol = 132 IPProtocolUDPLite IPProtocol = 136 IPProtocolMPLSInIP IPProtocol = 137 )
type LinkType ¶
type LinkType uint8
LinkType is an enumeration of link types, and acts as a decoder for any link type it supports.
const ( // According to pcap-linktype(7). LinkTypeNull LinkType = 0 LinkTypeEthernet LinkType = 1 LinkTypeTokenRing LinkType = 6 LinkTypeArcNet LinkType = 7 LinkTypeSLIP LinkType = 8 LinkTypePPP LinkType = 9 LinkTypeFDDI LinkType = 10 LinkTypeATM_RFC1483 LinkType = 100 LinkTypeRaw LinkType = 101 LinkTypePPP_HDLC LinkType = 50 LinkTypePPPEthernet LinkType = 51 LinkTypeC_HDLC LinkType = 104 LinkTypeIEEE802_11 LinkType = 105 LinkTypeFRelay LinkType = 107 LinkTypeLoop LinkType = 108 LinkTypeLinuxSLL LinkType = 113 LinkTypeLTalk LinkType = 104 LinkTypePFLog LinkType = 117 LinkTypePrismHeader LinkType = 119 LinkTypeIPOverFC LinkType = 122 LinkTypeSunATM LinkType = 123 LinkTypeIEEE80211Radio LinkType = 127 LinkTypeARCNetLinux LinkType = 129 LinkTypeLinuxIRDA LinkType = 144 LinkTypeLinuxLAPD LinkType = 177 )
type PktConn ¶
type PktConn struct {
// contains filtered or unexported fields
}
PktConn
func Dial ¶
func Dial(nic string, addr *RawPktAddr) (*PktConn, error)
Dial bind RawPktConn to nic for write
func Listen ¶
func Listen(nic string, addr *RawPktAddr) (*PktConn, error)
Listen bind RawPktConn to nic for read
func (*PktConn) LocalAddr ¶
func (pktConn *PktConn) LocalAddr() *RawPktAddr
LocalAddr return RawPktAddr Tpl for reading
func (*PktConn) Read ¶
Read get ethernet frame from pktConn.Iface filte by writeTplFrame and remoteTplAddr
func (*PktConn) ReadFrom ¶
func (pktConn *PktConn) ReadFrom(data []byte, raddr *RawPktAddr) (int, error)
ReadFrom output ethernet frame of RawPktConn to pktConn.Iface filter by addr
func (*PktConn) ReadFromMsg ¶
func (pktConn *PktConn) ReadFromMsg(data []byte) (laddr *RawPktAddr, raddr *RawPktAddr, ioBytes int, err error)
ReadFromMsg output ethernet frame of RawPktConn to pktConn.Iface filter by addr
func (*PktConn) RemoteAddr ¶
func (pktConn *PktConn) RemoteAddr() *RawPktAddr
RemoteAddr return RawPktAddr Tpl for writing
func (*PktConn) SetLocalAddr ¶
func (pktConn *PktConn) SetLocalAddr(addr *RawPktAddr) error
SetLocalAddr set read/write local RawPktAddr
func (*PktConn) SetPromisc ¶
SetPromisc set PktConn iface to Promisc flag
func (*PktConn) SetReadTimeOut ¶
SetReadTimeOut return old timeout
func (*PktConn) SetRemoteAddr ¶
func (pktConn *PktConn) SetRemoteAddr(addr *RawPktAddr) error
SetRemoteAddr
func (*PktConn) SetTimeOut ¶
SetTimeOut return old timeout of read/write
func (*PktConn) SetWriteTimeOut ¶
SetWriteTimeOut return old timeout
type RawPktAddr ¶
type RawPktAddr struct { HardwareAddr net.HardwareAddr // mac address of packet, eg., ff:ff:ff:ff:ff:ff / 00:e0:4c:68:04:1d IPAddr net.IP // ip of packet, eg., 255.255.255.255 / 8.8.8.8 IPPort int // port of packet, eg., 19818 / 53 }
RawPktAddr
var RawPktAddrBroadcast *RawPktAddr
var RawPktAddrZero *RawPktAddr
func NewPktAddr ¶
func NewPktAddr() *RawPktAddr
func ResolveRawPktAddr ¶
func ResolveRawPktAddr(mac, addr, port string) (pktAddr *RawPktAddr, err error)
ResolveRawPktAddr parse strings
func (*RawPktAddr) Match ¶
func (pktAddr *RawPktAddr) Match(addr *RawPktAddr) bool
Match compare two RawPktAddr, check on no-zero local/remote HwAddr/IP/Port return true for all match nil match to all
type RawPktConn ¶
type RawPktConn struct {
// contains filtered or unexported fields
}
RawPktConn
func Open ¶
func Open(nic string) (*RawPktConn, error)
Open bind RawPktConn to rawPktConn.iface
return *RawPktConn and error
func (*RawPktConn) ReadFromAddr ¶
func (rawPktConn *RawPktConn) ReadFromAddr(lfaddr *RawPktAddr, rfaddr *RawPktAddr, payload []byte) (laddr *RawPktAddr, raddr *RawPktAddr, ioBytes int, err error)
ReadFromAddr encode and write rawPktFrame full ethernet frame lfaddr/rfaddr used for package filter, nil for match all return local/remote RawPktAddr and error
func (*RawPktConn) SetPromisc ¶
func (rawPktConn *RawPktConn) SetPromisc(flag bool) (oldflag bool, err error)
SetPromisc set rawPktConn iface to Promisc flag
func (*RawPktConn) SetReadTimeOut ¶
func (rawPktConn *RawPktConn) SetReadTimeOut(val int) int
SetReadTimeOut return old timeout
func (*RawPktConn) SetTimeOut ¶
func (rawPktConn *RawPktConn) SetTimeOut(val int) (int, int)
SetTimeOut return old timeout
func (*RawPktConn) SetWriteTimeOut ¶
func (rawPktConn *RawPktConn) SetWriteTimeOut(val int) int
SetWriteTimeOut return old timeout
func (*RawPktConn) WriteToAddr ¶
func (rawPktConn *RawPktConn) WriteToAddr(laddr *RawPktAddr, raddr *RawPktAddr, payload []byte) (int, error)
WriteToAddr encode and write rawPktFrame full ethernet frame laddr/raddr should no be nil return bytes out and error