From eaefc7bac8e6cc3dc386b130ce0c09ff2887c723 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 27 Sep 2022 12:51:55 -0700 Subject: [PATCH] Support ipv6 ips for hextoip conversion (#442) --- pkg/inputs/snmp/util/util.go | 2 ++ pkg/inputs/snmp/util/util_test.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/inputs/snmp/util/util.go b/pkg/inputs/snmp/util/util.go index f06301d1..eacba53c 100644 --- a/pkg/inputs/snmp/util/util.go +++ b/pkg/inputs/snmp/util/util.go @@ -310,6 +310,8 @@ and display it as a string 10.0.100.10 */ func hexToIP(bv []byte) (int64, string, map[string]string) { switch len(bv) { + case 16: + return 0, net.IP(bv).String(), nil case 8: return 0, fmt.Sprintf("%d.%d.%d.%d", binary.BigEndian.Uint16(bv[0:2]), diff --git a/pkg/inputs/snmp/util/util_test.go b/pkg/inputs/snmp/util/util_test.go index 050627d9..8d460820 100644 --- a/pkg/inputs/snmp/util/util_test.go +++ b/pkg/inputs/snmp/util/util_test.go @@ -148,8 +148,9 @@ func TestHexToIP(t *testing.T) { l := lt.NewTestContextL(logger.NilContext, t) tests := map[string][]byte{ - "10.0.100.10": []byte{0x00, 0x0a, 0x00, 0x00, 0x00, 0x64, 0x00, 0x0a}, - "10.0.100.11": []byte{0x0a, 0x00, 0x64, 0x0b}, + "10.0.100.10": []byte{0x00, 0x0a, 0x00, 0x00, 0x00, 0x64, 0x00, 0x0a}, + "10.0.100.11": []byte{0x0a, 0x00, 0x64, 0x0b}, + "2001:504:0:2::6169:1": []byte{0x20, 0x01, 0x05, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x61, 0x69, 0x00, 0x01}, } for expt, in := range tests {