Skip to content

Commit

Permalink
Expose IP_PKTINFO Control Message on Android
Browse files Browse the repository at this point in the history
The commit nix-rust#1222 added the very
useful Ipv4PktInfo to allow `sendmsg` to define the origin of the ip.

Unfortunattely, it didn't add the struct to Android target devices as
well. This commit adds the `target_os = "android"` checks on the same
place to allow the compilation to work for the following archs tested:

- `cross build --target aarch64-linux-android`
- `cross build --target x86_64-linux-android`
- `cross build --target armv7-linux-androideabi`
  • Loading branch information
bltavares committed Jun 30, 2020
1 parent 2c42b30 commit 46df7b9
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/sys/socket/mod.rs
Expand Up @@ -724,7 +724,8 @@ pub enum ControlMessage<'a> {
/// [`ip(7)`](http://man7.org/linux/man-pages/man7/ip.7.html) man page.
#[cfg(any(target_os = "linux",
target_os = "macos",
target_os = "netbsd"))]
target_os = "netbsd",
target_os = "android"))]
Ipv4PacketInfo(&'a libc::in_pktinfo),

/// Configure the sending addressing and interface for v6
Expand All @@ -734,7 +735,8 @@ pub enum ControlMessage<'a> {
#[cfg(any(target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "freebsd"))]
target_os = "freebsd",
target_os = "android"))]
Ipv6PacketInfo(&'a libc::in6_pktinfo),
}

Expand Down Expand Up @@ -818,10 +820,11 @@ impl<'a> ControlMessage<'a> {
gso_size as *const _ as *const u8
},
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "android"))]
ControlMessage::Ipv4PacketInfo(info) => info as *const _ as *const u8,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd"))]
target_os = "netbsd", target_os = "freebsd",
target_os = "android"))]
ControlMessage::Ipv6PacketInfo(info) => info as *const _ as *const u8,
};
unsafe {
Expand Down Expand Up @@ -864,10 +867,11 @@ impl<'a> ControlMessage<'a> {
mem::size_of_val(gso_size)
},
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "android"))]
ControlMessage::Ipv4PacketInfo(info) => mem::size_of_val(info),
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd"))]
target_os = "netbsd", target_os = "freebsd",
target_os = "android"))]
ControlMessage::Ipv6PacketInfo(info) => mem::size_of_val(info),
}
}
Expand All @@ -886,10 +890,11 @@ impl<'a> ControlMessage<'a> {
#[cfg(target_os = "linux")]
ControlMessage::UdpGsoSegments(_) => libc::SOL_UDP,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "android"))]
ControlMessage::Ipv4PacketInfo(_) => libc::IPPROTO_IP,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd"))]
target_os = "netbsd", target_os = "freebsd",
target_os = "android"))]
ControlMessage::Ipv6PacketInfo(_) => libc::IPPROTO_IPV6,
}
}
Expand Down Expand Up @@ -919,10 +924,11 @@ impl<'a> ControlMessage<'a> {
libc::UDP_SEGMENT
},
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd"))]
target_os = "netbsd", target_os = "android"))]
ControlMessage::Ipv4PacketInfo(_) => libc::IP_PKTINFO,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd"))]
target_os = "netbsd", target_os = "freebsd",
target_os = "android"))]
ControlMessage::Ipv6PacketInfo(_) => libc::IPV6_PKTINFO,
}
}
Expand Down

0 comments on commit 46df7b9

Please sign in to comment.