From c13934f6a021586690bb37d73157f7a1d6fabc20 Mon Sep 17 00:00:00 2001 From: Twilight <48305952+BillyChen1@users.noreply.github.com> Date: Fri, 20 Oct 2023 19:16:05 +0800 Subject: [PATCH] example: use netip.Addr as key in XDP example Signed-off-by: chenqiming --- examples/xdp/main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/xdp/main.go b/examples/xdp/main.go index 38329a16f..123513b14 100644 --- a/examples/xdp/main.go +++ b/examples/xdp/main.go @@ -12,6 +12,7 @@ import ( "fmt" "log" "net" + "net/netip" "os" "strings" "time" @@ -70,12 +71,12 @@ func main() { func formatMapContents(m *ebpf.Map) (string, error) { var ( sb strings.Builder - key []byte + key netip.Addr val uint32 ) iter := m.Iterate() for iter.Next(&key, &val) { - sourceIP := net.IP(key) // IPv4 source address in network byte order. + sourceIP := key // IPv4 source address in network byte order. packetCount := val sb.WriteString(fmt.Sprintf("\t%s => %d\n", sourceIP, packetCount)) }