summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Pusateri <pusateri@bangj.com>2018-12-27 20:45:51 -0500
committerTom Pusateri <pusateri@bangj.com>2019-01-23 10:58:14 -0500
commit147f7911b8ed1255b340e3e8f074f52beef26e2e (patch)
tree6f972e6e6dba8964d992380052ac6ede2c849aff /src
parent148871e2b7a4ed2da6825a5fae455bd0bd0a0a43 (diff)
downloadnix-147f7911b8ed1255b340e3e8f074f52beef26e2e.zip
Add IP_RECVIF & IP_RECVDSTADDR.
Include IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
Diffstat (limited to 'src')
-rw-r--r--src/sys/socket/mod.rs110
-rw-r--r--src/sys/socket/sockopt.rs23
2 files changed, 131 insertions, 2 deletions
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 62c0ea74..64d2fc12 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -535,6 +535,22 @@ pub enum ControlMessage<'a> {
target_os = "macos"
))]
Ipv6PacketInfo(&'a libc::in6_pktinfo),
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ Ipv4RecvIf(&'a libc::sockaddr_dl),
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ Ipv4RecvDstAddr(&'a libc::in_addr),
/// Catch-all variant for unimplemented cmsg types.
#[doc(hidden)]
@@ -594,6 +610,26 @@ impl<'a> ControlMessage<'a> {
ControlMessage::Ipv6PacketInfo(pktinfo) => {
mem::size_of_val(pktinfo)
},
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvIf(dl) => {
+ mem::size_of_val(dl)
+ },
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvDstAddr(inaddr) => {
+ mem::size_of_val(inaddr)
+ },
ControlMessage::Unknown(UnknownCmsg(_, bytes)) => {
mem::size_of_val(bytes)
}
@@ -622,6 +658,22 @@ impl<'a> ControlMessage<'a> {
target_os = "macos"
))]
ControlMessage::Ipv6PacketInfo(_) => libc::IPPROTO_IPV6,
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvIf(_) => libc::IPPROTO_IP,
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvDstAddr(_) => libc::IPPROTO_IP,
ControlMessage::Unknown(ref cmsg) => cmsg.0.cmsg_level,
}
}
@@ -648,6 +700,22 @@ impl<'a> ControlMessage<'a> {
target_os = "macos"
))]
ControlMessage::Ipv6PacketInfo(_) => libc::IPV6_PKTINFO,
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvIf(_) => libc::IP_RECVIF,
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvDstAddr(_) => libc::IP_RECVDSTADDR,
ControlMessage::Unknown(ref cmsg) => cmsg.0.cmsg_type,
}
}
@@ -708,6 +776,26 @@ impl<'a> ControlMessage<'a> {
ControlMessage::Ipv6PacketInfo(pktinfo) => {
copy_bytes(pktinfo, buf)
}
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvIf(dl) => {
+ copy_bytes(dl, buf)
+ },
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ ControlMessage::Ipv4RecvDstAddr(inaddr) => {
+ copy_bytes(inaddr, buf)
+ },
ControlMessage::Unknown(_) => unreachable!(),
}
};
@@ -760,6 +848,28 @@ impl<'a> ControlMessage<'a> {
ControlMessage::Ipv4PacketInfo(
&*(data.as_ptr() as *const _))
}
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ (libc::IPPROTO_IP, libc::IP_RECVIF) => {
+ ControlMessage::Ipv4RecvIf(
+ &*(data.as_ptr() as *const _))
+ }
+ #[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+ ))]
+ (libc::IPPROTO_IP, libc::IP_RECVDSTADDR) => {
+ ControlMessage::Ipv4RecvDstAddr(
+ &*(data.as_ptr() as *const _))
+ }
(_, _) => {
ControlMessage::Unknown(UnknownCmsg(header, data))
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index 3cd46c66..1920987e 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -275,7 +275,8 @@ sockopt_impl!(Both, TcpCongestion, libc::IPPROTO_TCP, libc::TCP_CONGESTION, OsSt
target_os = "android",
target_os = "ios",
target_os = "linux",
- target_os = "macos"
+ target_os = "macos",
+ target_os = "netbsd",
))]
sockopt_impl!(Both, Ipv4PacketInfo, libc::IPPROTO_IP, libc::IP_PKTINFO, bool);
#[cfg(any(
@@ -283,9 +284,27 @@ sockopt_impl!(Both, Ipv4PacketInfo, libc::IPPROTO_IP, libc::IP_PKTINFO, bool);
target_os = "freebsd",
target_os = "ios",
target_os = "linux",
- target_os = "macos"
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
))]
sockopt_impl!(Both, Ipv6RecvPacketInfo, libc::IPPROTO_IPV6, libc::IPV6_RECVPKTINFO, bool);
+#[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+))]
+sockopt_impl!(Both, Ipv4RecvIf, libc::IPPROTO_IP, libc::IP_RECVIF, bool);
+#[cfg(any(
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd",
+))]
+sockopt_impl!(Both, Ipv4RecvDstAddr, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool);
/*