Beispiel #1
0
func OpenOffline(filename string) (*Pcap, error) {
	var pcap Pcap
	var errbuf *C.char = (*C.char)(C.calloc(1024, 1))
	pcap.pcap = C.pcap_open_offline(C.CString(filename), errbuf)
	if pcap.pcap == nil {
		return nil, errors.New(C.GoString(errbuf))
	}
	return &pcap, nil
}
Beispiel #2
0
// OpenOffline opens a file and returns its contents as a *Handle.
func OpenOffline(file string) (handle *Handle, err error) {
	buf := (*C.char)(C.calloc(errorBufferSize, 1))
	defer C.free(unsafe.Pointer(buf))
	cf := C.CString(file)
	defer C.free(unsafe.Pointer(cf))

	cptr := C.pcap_open_offline(cf, buf)
	if cptr == nil {
		return nil, errors.New(C.GoString(buf))
	}
	return &Handle{cptr: cptr}, nil
}
Beispiel #3
0
func Openoffline(file string) (handle *Pcap, err string) {
	var buf *C.char
	buf = (*C.char)(C.calloc(ERRBUF_SIZE, 1))
	h := new(Pcap)
	h.cptr = C.pcap_open_offline(C.CString(file), buf)
	if nil == h.cptr {
		handle = nil
		err = C.GoString(buf)
	} else {
		handle = h
	}
	C.free(unsafe.Pointer(buf))
	return
}
Beispiel #4
0
func Openoffline(file string) (ret *Pcap, msg string) {
	cfile := C.CString(file)
	defer C.free(unsafe.Pointer(cfile))

	var buf [ERRBUF_SIZE]byte
	cbuf := (*C.char)(unsafe.Pointer(&buf[0]))
	cptr := C.pcap_open_offline(cfile, cbuf)
	clen := C.strlen(cbuf)
	msg = string(buf[:clen])
	if cptr != nil {
		ret = &Pcap{cptr: cptr}
	}

	return
}
Beispiel #5
0
// OpenOffline opens a file and returns its contents as a *Handle.
func OpenOffline(file string) (handle *Handle, err error) {
	var buf *C.char
	buf = (*C.char)(C.calloc(errorBufferSize, 1))
	defer C.free(unsafe.Pointer(buf))
	cf := C.CString(file)
	defer C.free(unsafe.Pointer(cf))

	cptr := C.pcap_open_offline(cf, buf)
	if cptr == nil {
		return nil, errors.New(C.GoString(buf))
	}
	h := newHandle(cptr)
	h.activate.Do(func() {}) // skip activation
	return h, nil
}
Beispiel #6
0
// OpenFile opens a savefile for reading.
func (p *Pcap) OpenFile() error {
	var buf *C.char
	buf = (*C.char)(C.calloc(C.PCAP_ERRBUF_SIZE, 1))
	defer C.free(unsafe.Pointer(buf))

	cf := C.CString(p.FileName)
	defer C.free(unsafe.Pointer(cf))

	p.cptr = C.pcap_open_offline(cf, buf)
	if p.cptr == nil {
		return errors.New(C.GoString(buf))
	}
	p.Snaplen = int32(C.pcap_snapshot(p.cptr))
	return nil
}
Beispiel #7
0
// Openoffline
func OpenOffline(file string) (handle *Pcap, err error) {
	var buf *C.char
	buf = (*C.char)(C.calloc(ERRBUF_SIZE, 1))
	h := new(Pcap)

	cf := C.CString(file)
	defer C.free(unsafe.Pointer(cf))

	h.cptr = C.pcap_open_offline(cf, buf)
	if nil == h.cptr {
		handle = nil
		err = &pcapError{C.GoString(buf)}
	} else {
		handle = h
	}
	C.free(unsafe.Pointer(buf))
	return
}