本文整理匯總了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
}
}
}
示例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, ð, &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())
}
}
}