diff --git a/net/flowtrack/flowtrack.go b/net/flowtrack/flowtrack.go index 980e35445..8b3d799f7 100644 --- a/net/flowtrack/flowtrack.go +++ b/net/flowtrack/flowtrack.go @@ -56,7 +56,9 @@ func (t Tuple) SrcPort() uint16 { return t.srcPort } func (t Tuple) DstPort() uint16 { return t.dstPort } func (t Tuple) String() string { - return fmt.Sprintf("(%v %v => %v)", t.proto, t.src, t.dst) + return fmt.Sprintf("(%v %v => %v)", t.proto, + netip.AddrPortFrom(t.SrcAddr(), t.srcPort), + netip.AddrPortFrom(t.DstAddr(), t.dstPort)) } func (t Tuple) MarshalJSON() ([]byte, error) { diff --git a/net/flowtrack/flowtrack_test.go b/net/flowtrack/flowtrack_test.go index c9289c618..1a13f7753 100644 --- a/net/flowtrack/flowtrack_test.go +++ b/net/flowtrack/flowtrack_test.go @@ -100,10 +100,15 @@ func BenchmarkMapKeys(b *testing.B) { }) } -func TestJSON(t *testing.T) { +func TestStringJSON(t *testing.T) { v := MakeTuple(123, netip.MustParseAddrPort("1.2.3.4:5"), netip.MustParseAddrPort("6.7.8.9:10")) + + if got, want := v.String(), "(IPProto-123 1.2.3.4:5 => 6.7.8.9:10)"; got != want { + t.Errorf("String = %q; want %q", got, want) + } + got, err := json.Marshal(v) if err != nil { t.Fatal(err)