本文整理匯總了Golang中C.struct_pcap_pkthdr類的典型用法代碼示例。如果您正苦於以下問題:Golang struct_pcap_pkthdr類的具體用法?Golang struct_pcap_pkthdr怎麽用?Golang struct_pcap_pkthdr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了struct_pcap_pkthdr類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Matches
// Matches returns true if the given packet data matches this filter.
func (b *BPF) Matches(ci gopacket.CaptureInfo, data []byte) bool {
var hdr C.struct_pcap_pkthdr
hdr.ts.tv_sec = C.gopacket_time_secs_t(ci.Timestamp.Unix())
hdr.ts.tv_usec = C.gopacket_time_usecs_t(ci.Timestamp.Nanosecond() / 1000)
hdr.caplen = C.bpf_u_int32(len(data)) // Trust actual length over ci.Length.
hdr.len = C.bpf_u_int32(ci.Length)
dataptr := (*C.u_char)(unsafe.Pointer(&data[0]))
return C.pcap_offline_filter(&b.bpf, &hdr, dataptr) != 0
}
示例2: Dump
func (pd *PcapDumper) Dump(pkt *Packet) {
var pkthdr C.struct_pcap_pkthdr
pkthdr.ts.tv_sec = (C.__time_t)(pkt.Time.Sec)
pkthdr.ts.tv_usec = (C.__suseconds_t)(pkt.Time.Usec)
pkthdr.caplen = (C.bpf_u_int32)(pkt.Caplen)
pkthdr.len = (C.bpf_u_int32)(pkt.Len)
buf := (*C.char)(C.malloc((C.size_t)(len(pkt.Data))))
for i := 0; i < len(pkt.Data); i++ {
*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(i))) = pkt.Data[i]
}
C.pcap_dump((*C.u_char)(unsafe.Pointer(pd.cptr)), &pkthdr, (*C.u_char)(unsafe.Pointer(buf)))
}