예제 #1
0
파일: gopcap.go 프로젝트: cdshann/minimega
// NewLearner returns an IPMacLearner object bound to a particular interface.
func NewPCAP(dev string, file string) (*Pcap, error) {
	ret := &Pcap{}

	devC := C.CString(dev)
	fileC := C.CString(file)
	defer C.free(unsafe.Pointer(devC))
	defer C.free(unsafe.Pointer(fileC))

	handle := C.gopcapInit(devC)
	if handle == nil {
		return ret, fmt.Errorf("could not open device %v", dev)
	}
	ret.handle = unsafe.Pointer(handle)

	// start pcap
	dumperHandle := C.gopcapPrepare(handle, fileC)
	if dumperHandle == nil {
		C.gopcapClose(ret.handle, nil)
		return nil, fmt.Errorf("could not open output file %v", file)
	}
	ret.dumperHandle = unsafe.Pointer(dumperHandle)

	go C.gopcapCapture(handle, dumperHandle)

	return ret, nil
}
예제 #2
0
파일: gopcap.go 프로젝트: npe9/minimega
// NewLearner returns an IPMacLearner object bound to a particular interface.
func NewPCAP(dev string, file string) (*Pcap, error) {
	ret := &Pcap{}
	p := C.CString(dev)
	handle := C.gopcapInit(p)
	C.free(unsafe.Pointer(p))
	if handle == nil {
		return ret, fmt.Errorf("could not open device %v", dev)
	}
	ret.handle = unsafe.Pointer(handle)

	// start pcap
	dumperHandle := C.gopcapPrepare(handle, C.CString(file))
	C.free(unsafe.Pointer(p))
	if dumperHandle == nil {
		return ret, fmt.Errorf("could not open output file %v", file)
	}
	ret.dumperHandle = unsafe.Pointer(dumperHandle)

	go C.gopcapCapture(handle, dumperHandle)

	return ret, nil
}