Skip to content

Commit

Permalink
example: change key type of xdp example
Browse files Browse the repository at this point in the history
Signed-off-by: chenqiming <[email protected]>
  • Loading branch information
BillyChen1 committed Oct 19, 2023
1 parent 54f6a2b commit f9d6777
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions examples/xdp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit f9d6777

Please sign in to comment.