Skip to content

Commit

Permalink
example: use netip.Addr as key in XDP example
Browse files Browse the repository at this point in the history
Signed-off-by: chenqiming <[email protected]>
  • Loading branch information
BillyChen1 authored Oct 20, 2023
1 parent 0d47e51 commit c13934f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/xdp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"log"
"net"
"net/netip"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit c13934f

Please sign in to comment.