本文整理汇总了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)))
}