本文整理汇总了Golang中github.com/vtolstov/gopacket.NewPacket函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPacket函数的具体用法?Golang NewPacket怎么用?Golang NewPacket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPacket函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestPacketDot11DataARP
func TestPacketDot11DataARP(t *testing.T) {
p := gopacket.NewPacket(testPacketDot11DataARP, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11Data, LayerTypeLLC, LayerTypeSNAP, LayerTypeARP}, t)
if got, ok := p.Layer(LayerTypeARP).(*ARP); ok {
want := &ARP{
BaseLayer: BaseLayer{
Contents: []uint8{0x0, 0x1, 0x8, 0x0, 0x6, 0x4, 0x0, 0x1, 0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52, 0xa9, 0xfe, 0xf7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x43, 0x8, 0xe, 0x36},
Payload: []uint8{},
},
AddrType: 0x1,
Protocol: 0x800,
HwAddressSize: 0x6,
ProtAddressSize: 0x4,
Operation: 0x1,
SourceHwAddress: []uint8{0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52},
SourceProtAddress: []uint8{0xa9, 0xfe, 0xf7, 0x0},
DstHwAddress: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
DstProtAddress: []uint8{0x43, 0x8, 0xe, 0x36},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("ARP packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:29,代码来源:dot11_test.go
示例2: TestPacketIPSecESP
func TestPacketIPSecESP(t *testing.T) {
p := gopacket.NewPacket(testPacketIPSecESP, LinkTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIPSecESP}, t)
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:7,代码来源:ipsec_test.go
示例3: TestPacketDot11DataIP
func TestPacketDot11DataIP(t *testing.T) {
p := gopacket.NewPacket(testPacketDot11DataIP, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11Data, LayerTypeLLC, LayerTypeSNAP, LayerTypeIPv4, LayerTypeUDP, gopacket.LayerTypePayload}, t)
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:7,代码来源:dot11_test.go
示例4: TestPacketUSB0
func TestPacketUSB0(t *testing.T) {
p := gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeUSB, LayerTypeUSBInterrupt}, t)
if got, ok := p.Layer(LayerTypeUSB).(*USB); ok {
want := &USB{
BaseLayer: BaseLayer{
Contents: []uint8{0x0, 0x38, 0x4a, 0x3b, 0x0, 0x88, 0xff, 0xff, 0x43, 0x1, 0x81, 0x1, 0x2, 0x0, 0x2d, 0x0, 0xc0, 0xd3, 0x5b, 0x50, 0x0, 0x0, 0x0, 0x0, 0x8a, 0x85, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0},
Payload: []uint8{0x4},
},
ID: 0xffff88003b4a3800,
EventType: USBEventTypeComplete,
TransferType: USBTransportTypeInterrupt,
Direction: 0x1,
EndpointNumber: 0x1,
DeviceAddress: 0x1,
BusID: 0x2,
TimestampSec: 1348195264,
TimestampUsec: 689546,
Setup: false,
Data: true,
Status: 0,
UrbLength: 0x1,
UrbDataLength: 0x1,
}
if !reflect.DeepEqual(got, want) {
t.Errorf("USB packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:35,代码来源:usb_test.go
示例5: TestPacketP6196
func TestPacketP6196(t *testing.T) {
p := gopacket.NewPacket(testPacketP6196, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11WEP}, t)
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:8,代码来源:dot11_test.go
示例6: TestPacketPrism
func TestPacketPrism(t *testing.T) {
p := gopacket.NewPacket(testPacketPrism, LinkTypePrismHeader, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypePrismHeader, LayerTypeDot11, LayerTypeDot11MgmtProbeReq}, t)
if got, ok := p.Layer(LayerTypePrismHeader).(*PrismHeader); ok {
want := &PrismHeader{
BaseLayer: BaseLayer{
Contents: []uint8{0x44, 0x0, 0x0, 0x0, 0x90, 0x0, 0x0, 0x0, 0x72, 0x61, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x1, 0x0, 0x0, 0x0, 0x4, 0x0, 0xf9, 0xc1, 0x29, 0x0, 0x44, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x3, 0x0, 0x0, 0x0, 0x4, 0x0, 0xa, 0x0, 0x0, 0x0, 0x44, 0x0, 0x4, 0x0, 0x0, 0x0, 0x4, 0x0, 0xe1, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x6, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x7, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0x8, 0x0, 0x0, 0x0, 0x4, 0x0, 0x2, 0x0, 0x0, 0x0, 0x44, 0x0, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x0, 0xa, 0x0, 0x0, 0x0, 0x4, 0x0, 0x7e, 0x0, 0x0, 0x0},
Payload: []uint8{0x40, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xfa, 0x0, 0xad, 0x79, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x41, 0x0, 0x0, 0x1, 0x4, 0x2, 0x4, 0xb, 0x16, 0x32, 0x8, 0xc, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x1, 0x2d, 0x1a, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xdd, 0x9, 0x0, 0x10, 0x18, 0x2, 0x0, 0x0, 0x10, 0x0, 0x0, 0xdd, 0x1e, 0x0, 0x90, 0x4c, 0x33, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, Code: 0x44, Length: 0x90, DeviceName: "ra0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
Values: []PrismValue{
PrismValue{DID: PrismDIDType1HostTime, Status: 0x0, Length: 0x4, Data: []uint8{0xf9, 0xc1, 0x29, 0x0}},
PrismValue{DID: PrismDIDType1MACTime, Status: 0x0, Length: 0x0, Data: []uint8{}},
PrismValue{DID: PrismDIDType1Channel, Status: 0x0, Length: 0x4, Data: []uint8{0xa, 0x0, 0x0, 0x0}},
PrismValue{DID: PrismDIDType1RSSI, Status: 0x0, Length: 0x4, Data: []uint8{0xe1, 0xff, 0xff, 0xff}},
PrismValue{DID: 0x0, Status: 0x0, Length: 0x0, Data: []uint8{}},
PrismValue{DID: PrismDIDType1Signal, Status: 0x0, Length: 0x4, Data: []uint8{0x0, 0x0, 0x0, 0x0}},
PrismValue{DID: PrismDIDType1Noise, Status: 0x0, Length: 0x4, Data: []uint8{0x0, 0x0, 0x0, 0x0}},
PrismValue{DID: PrismDIDType1Rate, Status: 0x0, Length: 0x4, Data: []uint8{0x2, 0x0, 0x0, 0x0}},
PrismValue{DID: PrismDIDType1TransmittedFrameIndicator, Status: 0x0, Length: 0x0, Data: []uint8{}},
PrismValue{DID: PrismDIDType1FrameLength, Status: 0x0, Length: 0x4, Data: []uint8{0x7e, 0x0, 0x0, 0x0}},
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("RadioTap packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
}
if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok {
want := &Dot11{
BaseLayer: BaseLayer{
Contents: []uint8{0x40, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xfa, 0x0, 0xad, 0x79, 0xe8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xa0, 0x41},
Payload: []uint8{0x0, 0x0, 0x1, 0x4, 0x2, 0x4, 0xb, 0x16, 0x32, 0x8, 0xc, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x1, 0x2d, 0x1a, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7f, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xdd, 0x9, 0x0, 0x10, 0x18, 0x2, 0x0, 0x0, 0x10, 0x0, 0x0, 0xdd, 0x1e, 0x0, 0x90, 0x4c, 0x33, 0x2d, 0x11, 0x17, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
},
Type: 0x10,
Proto: 0x0,
Flags: 0x0,
DurationID: 0x0,
Address1: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
Address2: net.HardwareAddr{0xcc, 0xfa, 0x0, 0xad, 0x79, 0xe8},
Address3: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
Address4: net.HardwareAddr(nil),
SequenceNumber: 0x106,
FragmentNumber: 0x20,
Checksum: 0x0,
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:55,代码来源:prism_test.go
示例7: TestPacketICMPv6
func TestPacketICMPv6(t *testing.T) {
p := gopacket.NewPacket(testPacketICMPv6, LinkTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv6, LayerTypeICMPv6, gopacket.LayerTypePayload}, t)
if got, ok := p.Layer(LayerTypeIPv6).(*IPv6); ok {
want := &IPv6{
BaseLayer: BaseLayer{
Contents: []byte{0x60, 0x0, 0x0, 0x0, 0x0, 0x18,
0x3a, 0xff, 0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5,
0xff, 0xfe, 0x27, 0xb, 0x17, 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40},
Payload: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0, 0x26, 0x20,
0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb,
0x17},
},
Version: 6,
TrafficClass: 0,
FlowLabel: 0,
Length: 24,
NextHeader: IPProtocolICMPv6,
HopLimit: 255,
SrcIP: net.IP{0x26, 0x20, 0x0, 0x0, 0x10, 0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17},
DstIP: net.IP{0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x1f, 0xca, 0xff, 0xfe, 0xb3, 0x76, 0x40},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("IPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
} else {
t.Error("No IPv6 layer type found in packet")
}
if got, ok := p.Layer(LayerTypeICMPv6).(*ICMPv6); ok {
want := &ICMPv6{
BaseLayer: BaseLayer{
Contents: []byte{0x88, 0x0, 0x1e, 0xd6, 0x40, 0x0, 0x0, 0x0},
Payload: []byte{0x26, 0x20, 0x0, 0x0, 0x10,
0x5, 0x0, 0x0, 0x26, 0xbe, 0x5, 0xff, 0xfe, 0x27, 0xb, 0x17},
},
TypeCode: 0x8800,
Checksum: 0x1ed6,
TypeBytes: []byte{0x40, 0x0, 0x0, 0x0},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("ICMPv6 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
if got.TypeCode.String() != "NeighborAdvertisement(0)" {
t.Errorf("ICMPv6 type code, got %q want 'NeighborAdvertisement(0)'", got.TypeCode.String())
}
} else {
t.Error("No ICMPv6 layer type found in packet")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:53,代码来源:icmp6_test.go
示例8: TestPacketRadiotap0
func TestPacketRadiotap0(t *testing.T) {
p := gopacket.NewPacket(testPacketRadiotap0, LayerTypeRadioTap, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t)
rt := p.Layer(LayerTypeRadioTap).(*RadioTap)
if rt.ChannelFrequency != 2412 || rt.DBMAntennaSignal != -58 || rt.Antenna != 7 {
t.Error("Radiotap decode error")
}
if rt.Rate != 2 { // 500Kbps unit
t.Error("Radiotap Rate decode error")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:14,代码来源:radiotap_test.go
示例9: TestPacketDot11MgmtBeacon
func TestPacketDot11MgmtBeacon(t *testing.T) {
p := gopacket.NewPacket(testPacketDot11MgmtBeacon, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
expectedLayers := []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtBeacon}
for i := 0; i < 12; i++ {
expectedLayers = append(expectedLayers, LayerTypeDot11InformationElement)
}
checkLayers(p, expectedLayers, t)
if _, ok := p.Layer(LayerTypeDot11MgmtBeacon).(*Dot11MgmtBeacon); !ok {
t.Errorf("dot11 management beacon frame was expected")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:15,代码来源:dot11_test.go
示例10: getHwAddr
// getHwAddr is a hacky but effective way to get the destination hardware
// address for our packets. It does an ARP request for our gateway (if there is
// one) or destination IP (if no gateway is necessary), then waits for an ARP
// reply. This is pretty slow right now, since it blocks on the ARP
// request/reply.
func (s *scanner) getHwAddr() (net.HardwareAddr, error) {
start := time.Now()
arpDst := s.dst
if s.gw != nil {
arpDst = s.gw
}
// Prepare the layers to send for an ARP request.
eth := layers.Ethernet{
SrcMAC: s.iface.HardwareAddr,
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
EthernetType: layers.EthernetTypeARP,
}
arp := layers.ARP{
AddrType: layers.LinkTypeEthernet,
Protocol: layers.EthernetTypeIPv4,
HwAddressSize: 6,
ProtAddressSize: 4,
Operation: layers.ARPRequest,
SourceHwAddress: []byte(s.iface.HardwareAddr),
SourceProtAddress: []byte(s.src),
DstHwAddress: []byte{0, 0, 0, 0, 0, 0},
DstProtAddress: []byte(arpDst),
}
// Send a single ARP request packet (we never retry a send, since this
// is just an example ;)
if err := s.send(ð, &arp); err != nil {
return nil, err
}
// Wait 3 seconds for an ARP reply.
for {
if time.Since(start) > time.Second*3 {
return nil, fmt.Errorf("timeout getting ARP reply")
}
data, _, err := s.handle.ReadPacketData()
if err == pcap.NextErrorTimeoutExpired {
continue
} else if err != nil {
return nil, err
}
packet := gopacket.NewPacket(data, layers.LayerTypeEthernet, gopacket.NoCopy)
if arpLayer := packet.Layer(layers.LayerTypeARP); arpLayer != nil {
arp := arpLayer.(*layers.ARP)
if bytes.Equal(arp.SourceProtAddress, arpDst) {
return net.HardwareAddr(arp.SourceHwAddress), nil
}
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:53,代码来源:main.go
示例11: TestPacketEthernetOverGRE
func TestPacketEthernetOverGRE(t *testing.T) {
p := gopacket.NewPacket(testPacketEthernetOverGRE, LinkTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeGRE, LayerTypeEthernet, LayerTypeIPv4, LayerTypeICMPv4, gopacket.LayerTypePayload}, t)
if got, ok := p.Layer(LayerTypeGRE).(*GRE); ok {
want := &GRE{
BaseLayer: BaseLayer{testPacketEthernetOverGRE[34:38], testPacketEthernetOverGRE[38:]},
Protocol: EthernetTypeTransparentEthernetBridging,
}
if !reflect.DeepEqual(want, got) {
t.Errorf("GRE layer mismatch, \nwant %#v\ngot %#v\n", want, got)
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:16,代码来源:gre_test.go
示例12: TestPacketDot11MgmtAction
func TestPacketDot11MgmtAction(t *testing.T) {
p := gopacket.NewPacket(testPacketDot11MgmtAction, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtAction}, t)
if got, ok := p.Layer(LayerTypeDot11).(*Dot11); !ok {
t.Errorf("dot11 frame was not parsed")
} else if !got.ChecksumValid() {
t.Errorf("Dot11 packet processing failed: checksum failed")
}
if got, ok := p.Layer(LayerTypeDot11MgmtAction).(*Dot11MgmtAction); !ok {
t.Errorf("management action frame was not parsed")
} else if got.Contents[0] != 0 {
t.Errorf("action category was not spectrum management")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:17,代码来源:dot11_test.go
示例13: loadDNS
func loadDNS(dnspacket []byte, t *testing.T) *DNS {
p := gopacket.NewPacket(dnspacket, LinkTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4,
LayerTypeUDP, LayerTypeDNS}, t)
dnsL := p.Layer(LayerTypeDNS)
if dnsL == nil {
t.Error("No DNS Layer found")
}
dns, ok := dnsL.(*DNS)
if !ok {
return nil
}
return dns
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:19,代码来源:udp_test.go
示例14: TestInformationElement
func TestInformationElement(t *testing.T) {
bin := []byte{
0, 0,
0, 2, 1, 3,
221, 5, 1, 2, 3, 4, 5,
}
pkt := gopacket.NewPacket(bin, LayerTypeDot11InformationElement, gopacket.NoCopy)
buf := gopacket.NewSerializeBuffer()
var sLayers []gopacket.SerializableLayer
for _, l := range pkt.Layers() {
sLayers = append(sLayers, l.(*Dot11InformationElement))
}
if err := gopacket.SerializeLayers(buf, gopacket.SerializeOptions{}, sLayers...); err != nil {
t.Error(err.Error())
}
if !bytes.Equal(bin, buf.Bytes()) {
t.Error("build failed")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:20,代码来源:dot11_test.go
示例15: TestPacketRadiotap1
func TestPacketRadiotap1(t *testing.T) {
p := gopacket.NewPacket(testPacketRadiotap1, LayerTypeRadioTap, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t)
rt := p.Layer(LayerTypeRadioTap).(*RadioTap)
if rt.ChannelFrequency != 2412 || rt.DBMAntennaSignal != -36 || rt.Antenna != 5 {
t.Error("Radiotap decode error")
}
if !rt.MCS.Known.MCSIndex() || rt.MCS.MCS != 7 {
t.Error("Radiotap MCS error")
}
if !rt.MCS.Known.Bandwidth() || rt.MCS.Flags.Bandwidth() != 0 {
t.Error("Radiotap bandwidth error")
}
if !rt.MCS.Known.GuardInterval() || rt.MCS.Flags.ShortGI() {
t.Error("Radiotap GI error")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:20,代码来源:radiotap_test.go
示例16: TestUDPPacketDNS
func TestUDPPacketDNS(t *testing.T) {
p := gopacket.NewPacket(testUDPPacketDNS, LinkTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeDNS}, t)
if got, ok := p.TransportLayer().(*UDP); ok {
want := &UDP{
BaseLayer: BaseLayer{
Contents: []byte{0x0, 0x35, 0x89, 0x6d, 0x0, 0xd2, 0x75, 0x4a},
Payload: []byte{0xb8, 0xd8, 0x81, 0x80, 0x0, 0x1, 0x0,
0x7, 0x0, 0x0, 0x0, 0x0, 0x4, 0x78, 0x6b, 0x63, 0x64, 0x3, 0x63, 0x6f,
0x6d, 0x0, 0x0, 0xf, 0x0, 0x1, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0,
0x2, 0x58, 0x0, 0x18, 0x0, 0x14, 0x4, 0x41, 0x4c, 0x54, 0x32, 0x5, 0x41,
0x53, 0x50, 0x4d, 0x58, 0x1, 0x4c, 0x6, 0x47, 0x4f, 0x4f, 0x47, 0x4c,
0x45, 0xc0, 0x11, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0,
0x16, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x32, 0xa, 0x47, 0x4f,
0x4f, 0x47, 0x4c, 0x45, 0x4d, 0x41, 0x49, 0x4c, 0xc0, 0x11, 0xc0, 0xc,
0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0xb, 0x0, 0x1e, 0x6, 0x41,
0x53, 0x50, 0x4d, 0x58, 0x33, 0xc0, 0x53, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1,
0x0, 0x0, 0x2, 0x58, 0x0, 0xb, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d,
0x58, 0x34, 0xc0, 0x53, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2,
0x58, 0x0, 0xb, 0x0, 0x1e, 0x6, 0x41, 0x53, 0x50, 0x4d, 0x58, 0x35, 0xc0,
0x53, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0, 0x4, 0x0,
0xa, 0xc0, 0x2d, 0xc0, 0xc, 0x0, 0xf, 0x0, 0x1, 0x0, 0x0, 0x2, 0x58, 0x0,
0x9, 0x0, 0x14, 0x4, 0x41, 0x4c, 0x54, 0x31, 0xc0, 0x2d},
},
SrcPort: 53,
DstPort: 35181,
Length: 210,
Checksum: 30026,
sPort: []byte{0x0, 0x35},
dPort: []byte{0x89, 0x6d},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("UDP packet mismatch:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
} else {
t.Error("Transport layer packet not UDP")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:41,代码来源:udp_test.go
示例17: TestPacketIPSecAHTunnel
func TestPacketIPSecAHTunnel(t *testing.T) {
p := gopacket.NewPacket(testPacketIPSecAHTunnel, LinkTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeIPSecAH, LayerTypeIPv4, LayerTypeICMPv4, gopacket.LayerTypePayload}, t)
if got, ok := p.Layer(LayerTypeIPSecAH).(*IPSecAH); ok {
want := &IPSecAH{
Reserved: 0x0,
SPI: 0x101,
Seq: 1,
AuthenticationData: []byte{0xcc, 0xa4, 0x01, 0xda, 0x9e, 0xb4, 0xfb, 0x75, 0x10, 0xfe, 0x5a, 0x59},
}
want.BaseLayer = BaseLayer{testPacketIPSecAHTunnel[34:58], testPacketIPSecAHTunnel[58:]}
want.NextHeader = IPProtocolIPv4
want.HeaderLength = 0x4
want.ActualLength = 0x18
if !reflect.DeepEqual(want, got) {
t.Errorf("IPSecAH layer mismatch, \nwant %#v\ngot %#v\n", want, got)
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:22,代码来源:ipsec_test.go
示例18: TestDecodeUDPSFlow
func TestDecodeUDPSFlow(t *testing.T) {
p := gopacket.NewPacket(SFlowTestPacket1, LayerTypeEthernet, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeEthernet, LayerTypeIPv4, LayerTypeUDP, LayerTypeSFlow}, t)
if got, ok := p.TransportLayer().(*UDP); ok {
want := &UDP{
BaseLayer: BaseLayer{SFlowTestPacket1[34:42], SFlowTestPacket1[42:]},
sPort: []byte{199, 87},
dPort: []byte{24, 199},
SrcPort: 51031,
DstPort: 6343,
Checksum: 8763,
Length: 1448,
}
if !reflect.DeepEqual(want, got) {
t.Errorf("UDP layer mismatch, \nwant %#v\ngot %#v\n", want, got)
}
} else {
t.Error("Transport layer packet not UDP")
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:23,代码来源:sflow_test.go
示例19: TestPacketDot11CtrlAck
func TestPacketDot11CtrlAck(t *testing.T) {
p := gopacket.NewPacket(testPacketDot11CtrlAck, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11}, t)
if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok {
if !got.ChecksumValid() {
t.Errorf("Dot11 packet processing failed:\nchecksum failed. got :\n%#v\n\n", got)
}
}
if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok {
if !got.ChecksumValid() {
t.Errorf("Dot11 packet processing failed:\nchecksum failed. got :\n%#v\n\n", got)
}
want := &Dot11{
BaseLayer: BaseLayer{
Contents: []uint8{0xd4, 0x0, 0x0, 0x0, 0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52},
Payload: []uint8{},
},
Type: Dot11TypeCtrlAck,
Proto: 0x0,
Flags: 0x0,
DurationID: 0x0,
Address1: net.HardwareAddr{0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52},
Address2: net.HardwareAddr(nil),
Address3: net.HardwareAddr(nil),
Address4: net.HardwareAddr(nil),
Checksum: 0x8776e946,
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:37,代码来源:dot11_test.go
示例20: BenchmarkDecodePacketUSB0
func BenchmarkDecodePacketUSB0(b *testing.B) {
for i := 0; i < b.N; i++ {
gopacket.NewPacket(testPacketUSB0, LinkTypeLinuxUSB, gopacket.NoCopy)
}
}
开发者ID:vtolstov,项目名称:cloudmeta,代码行数:5,代码来源:usb_test.go
注:本文中的github.com/vtolstov/gopacket.NewPacket函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论