本文整理匯總了Golang中C.pcap_datalink函數的典型用法代碼示例。如果您正苦於以下問題:Golang pcap_datalink函數的具體用法?Golang pcap_datalink怎麽用?Golang pcap_datalink使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了pcap_datalink函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OpenActiveDevice
//Opens a pcap handle
func OpenActiveDevice(dev string, snaplen uint32, promisc bool, timeout_ms uint32, filter string) (*Pcap, error) {
var cbuf *C.char
cbuf = (*C.char)(C.calloc(ERRBUF_SIZE, 1))
handle := new(Pcap)
var cpromisc int32 = 0
if promisc {
cpromisc = 1
}
cdev := C.CString(dev)
defer C.free(unsafe.Pointer(cdev))
handle.cptr = C.pcap_open_live(cdev, C.int(snaplen), C.int(cpromisc), C.int(timeout_ms), cbuf)
if handle.cptr == nil {
return nil, errors.New(C.GoString(cbuf))
}
x := C.pcap_datalink(handle.cptr)
handle.linkLayer = uint16(x)
C.free(unsafe.Pointer(cbuf))
if filter != "" {
ret := int32(C.pcap_set_filter(handle.cptr, cdev, C.CString(filter), cbuf, ERRBUF_SIZE-1))
if ret != 0 {
C.free(unsafe.Pointer(handle.cptr))
return nil, errors.New(C.GoString(cbuf))
}
}
return handle, nil
}
示例2: Datalink
func (p *Pcap) Datalink() int {
return int(C.pcap_datalink(p.cptr))
}
示例3: LinkType
// LinkType returns pcap_datalink, as a layers.LinkType.
func (p *Handle) LinkType() layers.LinkType {
return layers.LinkType(C.pcap_datalink(p.cptr))
}
示例4: LinkType
// Return the link type of the capture handle (that is, the type of packets that
// come out of the packet source).
func (h *Handle) LinkType() packet.Type {
return packet.LinkType(uint32(C.pcap_datalink(h.pcap)))
}