-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
ff4ddca
commit a61288e
Showing
4 changed files
with
65 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters