Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IP_RECVIF & IP_RECVDSTADDR. #1002

Merged
merged 1 commit into from
Jan 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add IP_RECVIF & IP_RECVDSTADDR. Enable IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
([#1002](https://github.com/nix-rust/nix/pull/1002))
### Changed
### Fixed
### Removed
110 changes: 110 additions & 0 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
@@ -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))
23 changes: 21 additions & 2 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
@@ -275,17 +275,36 @@ 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(
target_os = "android",
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);


/*
Loading