tehmaze / netflow

NetFlow version 1, 5, 7, 8, 9 & 10 (IPFIX) support for Go
https://godoc.org/github.com/tehmaze/go-netflow
MIT License
80 stars 27 forks source link

SysUptime incorrectly parsed as nanosecond #5

Closed adamlamar closed 7 years ago

adamlamar commented 8 years ago

While parsing netflow v5, I noticed that the SysUptime field seems to be parsed incorrectly. Various documents</a/> describe SysUptime as the number of milliseconds since the device booted. In netflow5/packet.go, the code reads a 32-bit value and casts the value directly to a time.Duration, which leads them to be interpreted as nanoseconds:

h.SysUptime = time.Duration(u)

In order to interpret u as a number of milliseconds, one could do this instead:

h.SysUptime = time.Duration(u)*time.Millisecond

As an aside, the First and Last fields are based on SysUptime, but are uint32 values in the struct. What do you think about changing these to time.Duration and parsing them as milliseconds as well?

adamlamar commented 8 years ago

Also, I'm happy to submit a PR for this issue if that would be useful.

tehmaze commented 8 years ago

Yes, please.

adamlamar commented 7 years ago

Very cool, thanks for doing this! I lost track of it.