From f9d677780043d84916ca3bcc6f501a670658a673 Mon Sep 17 00:00:00 2001 From: chenqiming Date: Thu, 19 Oct 2023 22:15:56 +0800 Subject: [PATCH] example: change key type of xdp example Signed-off-by: chenqiming --- examples/xdp/main.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/xdp/main.go b/examples/xdp/main.go index 513cc93ee..123513b14 100644 --- a/examples/xdp/main.go +++ b/examples/xdp/main.go @@ -12,12 +12,12 @@ import ( "fmt" "log" "net" + "net/netip" "os" "strings" "time" "github.com/cilium/ebpf" - "github.com/cilium/ebpf/internal" "github.com/cilium/ebpf/link" ) @@ -71,14 +71,12 @@ func main() { func formatMapContents(m *ebpf.Map) (string, error) { var ( sb strings.Builder - key uint32 + key netip.Addr val uint32 ) iter := m.Iterate() for iter.Next(&key, &val) { - b := make([]byte, 4) - internal.NativeEndian.PutUint32(b, key) - sourceIP := net.IP(b) // 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)) }