packetcap / go-pcap

Packet capture library and tools in native go
Apache License 2.0
14 stars 4 forks source link

syscalls doesn't support `Timestamp` or `Length` #46

Open fs185143 opened 3 months ago

fs185143 commented 3 months ago

I noticed that for func (h *Handle) readPacketDataSyscall() (data []byte, ci gopacket.CaptureInfo, err error) the Timestamp and Length fields are not implemented

// TODO: add CaptureInfo, specifically:
//    capture timestamp
//    original packet length
ci = gopacket.CaptureInfo{
CaptureLength:  n,
InterfaceIndex: h.index,
}

This makes it hard to measure things such as byte rate.

Given that there is a "TODO" associated with this, I was wondering if you have a solution in mind? If not, I might be able to look into creating a PR for this.

deitch commented 3 months ago

Yeah it does. The original use case didn't need it, but I had it in mind, hence TODO 😁

look into creating a PR for this

I never argue with someone kindly willing to assist!

fs185143 commented 3 months ago

Yeah it does. The original use case didn't need it, but I had it in mind, hence TODO 😁

look into creating a PR for this

I never argue with someone kindly willing to assist!

Do you mind providing a summary of your thoughts/findings (if any) when looking into this before?

fs185143 commented 3 months ago

Worth taking a look at this

https://github.com/google/gopacket/blob/32ee38206866f44a74a6033ec26aeeb474506804/pcapgo/capture.go#L83-L100

Think this library actually fulfills my needs

deitch commented 3 months ago

Yeah, looks like they figured that part out.

We originally looked at that project; it required cgo. This project is native go.

fs185143 commented 3 months ago

We originally looked at that project; it required cgo. This project is native go.

I believe the pcapgo package is using Go only

deitch commented 3 months ago

I believe you are correct. There are limited capabilities for the native one. If either meets your need, great.