Skip to content

Commit 94011b2

Browse files
committed
Try original dst
Signed-off-by: Keith Mattix II <[email protected]>
1 parent 3a93893 commit 94011b2

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include = [
2929
[package.metadata.docs.rs]
3030
all-features = true
3131
rustdoc-args = ["--cfg", "docsrs"]
32-
targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"]
32+
targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"]
3333

3434
[package.metadata.playground]
3535
features = ["all"]

src/sys/windows.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub(crate) use windows_sys::Win32::Networking::WinSock::{
7777
IP_MREQ_SOURCE as IpMreqSource, IP_MULTICAST_IF, IP_MULTICAST_LOOP, IP_MULTICAST_TTL,
7878
IP_RECVTOS, IP_TOS, IP_TTL, LINGER as linger, MSG_OOB, MSG_PEEK, SO_BROADCAST, SO_ERROR,
7979
SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDBUF,
80-
SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
80+
SO_SNDTIMEO, SO_TYPE, TCP_NODELAY, SO_ORIGINAL_DST, IP6T_SO_ORIGINAL_DST, SOL_IP
8181
};
8282
pub(crate) const IPPROTO_IP: c_int = windows_sys::Win32::Networking::WinSock::IPPROTO_IP as c_int;
8383
pub(crate) const SOL_SOCKET: c_int = windows_sys::Win32::Networking::WinSock::SOL_SOCKET as c_int;
@@ -927,6 +927,38 @@ impl crate::Socket {
927927
}
928928
}
929929

930+
/// Get the value for the `SO_ORIGINAL_DST` option on this socket.
931+
///
932+
pub fn original_dst(&self) -> io::Result<SockAddr> {
933+
// Safety: `getsockopt` initialises the `SockAddr` for us.
934+
unsafe {
935+
SockAddr::try_init(|storage, len| {
936+
getsockopt::<>(self.as_raw(), SOL_IP, SO_ORIGINAL_DST)
937+
})
938+
}
939+
.map(|(_, addr)| addr)
940+
}
941+
942+
/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket.
943+
///
944+
#[cfg(feature = "all")]
945+
#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))]
946+
pub fn original_dst_ipv6(&self) -> io::Result<SockAddr> {
947+
// Safety: `getsockopt` initialises the `SockAddr` for us.
948+
unsafe {
949+
SockAddr::try_init(|storage, len| {
950+
syscall!(getsockopt(
951+
self.as_raw(),
952+
libc::SOL_IPV6,
953+
IP6T_SO_ORIGINAL_DST,
954+
storage.cast(),
955+
len
956+
))
957+
})
958+
}
959+
.map(|(_, addr)| addr)
960+
}
961+
930962
/// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW`
931963
/// option on this socket.
932964
///

0 commit comments

Comments
 (0)