当前位置: 首页>>代码示例>>Golang>>正文


Golang Packet.Data方法代码示例

本文整理汇总了Golang中github.com/google/gopacket.Packet.Data方法的典型用法代码示例。如果您正苦于以下问题:Golang Packet.Data方法的具体用法?Golang Packet.Data怎么用?Golang Packet.Data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/google/gopacket.Packet的用法示例。


在下文中一共展示了Packet.Data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: inputStream

//if it is the input stream to local machine
func inputStream(packet gopacket.Packet, Srcaddr *metrics.Address, Destaddr *metrics.Address) {
	//get the instance from the list which has the reverse srcaddr and the destaddr
	respdetail := string(packet.Data())
	if glog.V(1) {
		glog.Info("the length of the list before extract element:", httpinstancelist.Len())
	}

	for element := httpinstancelist.Front(); element != nil; element = element.Next() {
		httpinstance := element.Value.(*metrics.HttpTransaction)
		isreverse := ifreverse(httpinstance, Srcaddr, Destaddr)
		if isreverse {
			httpinstance.Timereceive = time.Now()
			//the units of time is ms
			responsetime := httpinstance.Timereceive.Sub(httpinstance.Timesend).Seconds() * 1000
			httpinstance.Respondtime = responsetime
			//store the respond detail
			glog.Info("respond info:", respdetail)
			httpinstance.Packetdetail.Responddetail = respdetail
			if glog.V(0) {
				glog.Infof("Respond duration:%vms", responsetime)
				glog.Infof("Get the response: %v", httpinstance)
				//glog.Info("detail:", httpinstance.Packetdetail)

			}
			httpinstancelist.Remove(element)
			//??how to use generic to realize the push function of different type
			//jsoninfo, _ := json.Marshal(httpinstance)
			//the type should be the ip of this machine
			//the first parameter is index the second one is type
			//err := ESClient.Push(jsoninfo, "packetagent", localip)
			//measurement := "respondtime"
			glog.Info("send the respondtime measurement")
			err := Influxstorage.AddStats("type_packet", "abcde", httpinstance)
			if err != nil {
				glog.Info("error to push")
			}
			break
		}
	}

}
开发者ID:wangzhezhe,项目名称:cpmonitor,代码行数:42,代码来源:packetcollect.go

示例2: handlePacket

func handlePacket(packet gopacket.Packet) {
	var eth layers.Ethernet
	var ip4 layers.IPv4
	var udp layers.UDP
	var payload gopacket.Payload
	parser := gopacket.NewDecodingLayerParser(layers.LayerTypeEthernet, &eth, &ip4, &udp, &payload)
	decoded := []gopacket.LayerType{}

	err := parser.DecodeLayers(packet.Data(), &decoded)
	if err != nil {
		log.Printf("Decoding error:%v\n", err)
	}
	for _, layerType := range decoded {
		switch layerType {
		case layers.LayerTypeEthernet:
			fmt.Println("    Eth ", eth.SrcMAC, eth.DstMAC)
		case layers.LayerTypeIPv4:
			fmt.Println("    IP4 ", ip4.SrcIP, ip4.DstIP)
		case layers.LayerTypeUDP:
			fmt.Println("    UDP ", udp.SrcPort, udp.DstPort, payload.GoString())
		}

	}
}
开发者ID:dark-lab,项目名称:dhcpkiller,代码行数:24,代码来源:main.go


注:本文中的github.com/google/gopacket.Packet.Data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。