Skip to content

Commit e3c023b

Browse files
committed
add IPAddrFromNetIP function to allow convertion from NetIP to IPAddr
1 parent 80443b0 commit e3c023b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pkg/exporter/kafka_json_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import (
1313
"github.com/stretchr/testify/require"
1414
)
1515

16+
// IPAddrFromNetIP returns IPAddr from net.IP
17+
func IPAddrFromNetIP(netIP net.IP) flow.IPAddr {
18+
var arr [net.IPv6len]uint8
19+
copy(arr[:], (netIP)[0:net.IPv6len])
20+
return arr
21+
}
22+
1623
func TestJSONConversion(t *testing.T) {
1724
wc := writerCapturer{}
1825
kj := KafkaJSON{Writer: &wc}
@@ -22,8 +29,8 @@ func TestJSONConversion(t *testing.T) {
2229
record.Direction = 1
2330
record.SrcMac = [...]byte{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}
2431
record.DstMac = [...]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}
25-
record.SrcAddr = *(*flow.IPAddr)(net.ParseIP("192.1.2.3")[0:16])
26-
record.DstAddr = *(*flow.IPAddr)(net.ParseIP("aabb:ccdd:eeff::2233")[0:16])
32+
record.SrcAddr = IPAddrFromNetIP(net.ParseIP("192.1.2.3"))
33+
record.DstAddr = IPAddrFromNetIP(net.ParseIP("aabb:ccdd:eeff::2233"))
2734
record.SrcPort = 4321
2835
record.DstPort = 1234
2936
record.Protocol = 210

0 commit comments

Comments
 (0)