Ejemplo n.º 1
0
func (p *Pcap) Inject(data []byte) (err os.Error) {
	if C.pcap_inject(p.cptr, unsafe.Pointer(&data[0]),
		(C.size_t)(len(data))) == -1 {
		err = os.NewError(p.Geterror())
	}

	return
}
Ejemplo n.º 2
0
func (p *Pcap) Inject(data []byte) (err error) {
	buf := (*C.char)(C.malloc((C.size_t)(len(data))))

	for i := 0; i < len(data); i++ {
		*(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(buf)) + uintptr(i))) = data[i]
	}

	if -1 == C.pcap_inject(p.cptr, unsafe.Pointer(buf), (C.size_t)(len(data))) {
		err = p.Geterror()
	}
	C.free(unsafe.Pointer(buf))
	return
}