Skip to content

Commit

Permalink
examples: Convert IPv4 addresses from big endian (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooladkhay authored Jan 24, 2023
1 parent 46b3a24 commit 594980b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/xdp-drop/xdp-drop-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn try_xdp_firewall(ctx: XdpContext) -> Result<u32, ()> {
}

let ipv4hdr: *const Ipv4Hdr = unsafe { ptr_at(&ctx, EthHdr::LEN)? };
let source = unsafe { (*ipv4hdr).src_addr };
let source = u32::from_be(unsafe { (*ipv4hdr).src_addr });

// (3)
let action = if block_ip(source) {
Expand Down
2 changes: 1 addition & 1 deletion examples/xdp-log/xdp-log-ebpf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn try_xdp_firewall(ctx: XdpContext) -> Result<u32, ()> {
}

let ipv4hdr: *const Ipv4Hdr = unsafe { ptr_at(&ctx, EthHdr::LEN)? };
let source_addr = unsafe { (*ipv4hdr).src_addr };
let source_addr = u32::from_be(unsafe { (*ipv4hdr).src_addr });

let source_port = match unsafe { (*ipv4hdr).proto } {
IpProto::Tcp => {
Expand Down

0 comments on commit 594980b

Please sign in to comment.