Skip to content

Commit a131ca5

Browse files
committed
Add _v4 suffix Socket::original_dst
As it only works on IPv4 sockets.
1 parent a2be960 commit a131ca5

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/socket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,8 +1681,8 @@ impl Socket {
16811681
target_os = "windows",
16821682
)
16831683
))]
1684-
pub fn original_dst(&self) -> io::Result<SockAddr> {
1685-
sys::original_dst(self.as_raw())
1684+
pub fn original_dst_v4(&self) -> io::Result<SockAddr> {
1685+
sys::original_dst_v4(self.as_raw())
16861686
}
16871687
}
16881688

src/sys/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ pub(crate) const fn to_mreqn(
13801380
feature = "all",
13811381
any(target_os = "android", target_os = "fuchsia", target_os = "linux")
13821382
))]
1383-
pub(crate) fn original_dst(fd: Socket) -> io::Result<SockAddr> {
1383+
pub(crate) fn original_dst_v4(fd: Socket) -> io::Result<SockAddr> {
13841384
// Safety: `getsockopt` initialises the `SockAddr` for us.
13851385
unsafe {
13861386
SockAddr::try_init(|storage, len| {
@@ -1401,7 +1401,7 @@ pub(crate) fn original_dst(fd: Socket) -> io::Result<SockAddr> {
14011401
/// This value contains the original destination IPv6 address of the connection
14021402
/// redirected using `ip6tables` `REDIRECT` or `TPROXY`.
14031403
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
1404-
pub(crate) fn original_dst_ipv6(fd: Socket) -> io::Result<SockAddr> {
1404+
pub(crate) fn original_dst_v6(fd: Socket) -> io::Result<SockAddr> {
14051405
// Safety: `getsockopt` initialises the `SockAddr` for us.
14061406
unsafe {
14071407
SockAddr::try_init(|storage, len| {

src/sys/windows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ pub(crate) fn to_mreqn(
883883
}
884884

885885
#[cfg(feature = "all")]
886-
pub(crate) fn original_dst(socket: Socket) -> io::Result<SockAddr> {
886+
pub(crate) fn original_dst_v4(socket: Socket) -> io::Result<SockAddr> {
887887
unsafe {
888888
SockAddr::try_init(|storage, len| {
889889
syscall!(
@@ -903,7 +903,7 @@ pub(crate) fn original_dst(socket: Socket) -> io::Result<SockAddr> {
903903
}
904904

905905
#[cfg(feature = "all")]
906-
pub(crate) fn original_dst_ipv6(socket: Socket) -> io::Result<SockAddr> {
906+
pub(crate) fn original_dst_v6(socket: Socket) -> io::Result<SockAddr> {
907907
unsafe {
908908
SockAddr::try_init(|storage, len| {
909909
syscall!(

tests/socket.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,21 +1654,21 @@ fn header_included_ipv6() {
16541654
target_os = "windows"
16551655
)
16561656
))]
1657-
fn original_dst() {
1657+
fn original_dst_v4() {
16581658
let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap();
16591659
#[cfg(not(target_os = "windows"))]
16601660
let expected = Some(libc::ENOENT);
16611661
#[cfg(target_os = "windows")]
16621662
let expected = Some(windows_sys::Win32::Networking::WinSock::WSAEINVAL);
16631663

1664-
match socket.original_dst() {
1665-
Ok(_) => panic!("original_dst on non-redirected socket should fail"),
1664+
match socket.original_dst_v4() {
1665+
Ok(_) => panic!("original_dst_v4 on non-redirected socket should fail"),
16661666
Err(err) => assert_eq!(err.raw_os_error(), expected),
16671667
}
16681668

16691669
let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap();
1670-
match socket.original_dst() {
1671-
Ok(_) => panic!("original_dst on non-redirected socket should fail"),
1670+
match socket.original_dst_v4() {
1671+
Ok(_) => panic!("original_dst_v4 on non-redirected socket should fail"),
16721672
Err(err) => assert_eq!(err.raw_os_error(), expected),
16731673
}
16741674
}

0 commit comments

Comments
 (0)