Files
goflow2/decoders/utils/types.go
Vincent Bernat a61288eb19 decoders: fix sflow parsing of IP and MAC addresses (#261)
Due to IP and MAC addresses being a non-standard type, utils.BinaryRead
was not able to decode them. Move these two types inside utils.go and
teach BinaryRead to use them.

Co-authored-by: lspgn <lspgn@users.noreply.github.com>
2024-01-06 00:59:53 -08:00

21 lines
463 B
Go

package utils
import (
"fmt"
"net"
"net/netip"
)
type MacAddress []byte // purely for the formatting purpose
func (s *MacAddress) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", net.HardwareAddr([]byte(*s)).String())), nil
}
type IPAddress []byte // purely for the formatting purpose
func (s IPAddress) MarshalJSON() ([]byte, error) {
ip, _ := netip.AddrFromSlice([]byte(s))
return []byte(fmt.Sprintf("\"%s\"", ip.String())), nil
}