示例#1
0
文件: pcap.go 项目: jvortega/mimir
//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
0
文件: pcap.go 项目: dlintw/gopcap
func (p *Pcap) Datalink() int {
	return int(C.pcap_datalink(p.cptr))
}
示例#3
0
文件: pcap.go 项目: donckers/gopacket
// LinkType returns pcap_datalink, as a layers.LinkType.
func (p *Handle) LinkType() layers.LinkType {
	return layers.LinkType(C.pcap_datalink(p.cptr))
}
示例#4
0
文件: capture.go 项目: kelixin/go.pkt
// 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)))
}