示例#1
0
文件: pcap.go 项目: khalily/gopacket
// 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
}
示例#2
0
文件: pcap.go 项目: huyan/gopcap
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
}
示例#3
0
文件: capture.go 项目: kelixin/go.pkt
// 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
}
示例#4
0
文件: pcap.go 项目: songgao/gopcap
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
}
示例#5
0
文件: pcap.go 项目: donckers/gopacket
// 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
}