// WritePacketData calls pcap_sendpacket, injecting the given data into the pcap handle. func (p *Handle) WritePacketData(data []byte) (err error) { buf := C.CString(string(data)) defer C.free(unsafe.Pointer(buf)) if -1 == C.pcap_sendpacket(p.cptr, (*C.u_char)(unsafe.Pointer(buf)), (C.int)(len(data))) { err = p.Error() } return }
func (p *Pcap) Inject(data []byte) (err error) { buf := C.CString(string(data)) if -1 == C.pcap_sendpacket(p.cptr, (*C.u_char)(unsafe.Pointer(buf)), (C.int)(len(data))) { err = p.Geterror() } C.free(unsafe.Pointer(buf)) return }
// Inject a packet in the packet source. func (h *Handle) Inject(buf []byte) error { cbuf := (*C.u_char)(&buf[0]) blen := C.int(len(buf)) err := C.pcap_sendpacket(h.pcap, cbuf, blen) if err < 0 { return fmt.Errorf("Could not inject packet: %s", h.get_error()) } return nil }
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_sendpacket(p.cptr, (*C.u_char)(unsafe.Pointer(buf)), (C.int)(len(data))) { err = p.Geterror() } C.free(unsafe.Pointer(buf)) return }
// WritePacketData calls pcap_sendpacket, injecting the given data into the pcap handle. func (p *Handle) WritePacketData(data []byte) (err error) { if -1 == C.pcap_sendpacket(p.cptr, (*C.u_char)(&data[0]), (C.int)(len(data))) { err = p.Error() } return }