Skip to content

Commit

Permalink
Support ipv6 ips for hextoip conversion (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
i3149 authored Sep 27, 2022
1 parent 9a49172 commit eaefc7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/inputs/snmp/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
5 changes: 3 additions & 2 deletions pkg/inputs/snmp/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit eaefc7b

Please sign in to comment.