Skip to content

Commit 273347d

Browse files
committed
Auto merge of #367 - justinlatimer:so-original-dst, r=kamalmarhubi
Add SO_ORIGINAL_DST In Linux, the SO_ORIGINAL_DST socket option can be used to get the original destination, which can be needed if the connection is translated by a NAT, i.e. iptables. In C, this information can be obtained by ``getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, &remote, &remote_len)`` and returns a ``sockaddr_in`` struct. I've added a binding for this option. Thanks!
2 parents d049c3f + 3954580 commit 273347d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/sys/socket/consts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ mod os {
5959
pub const SO_TIMESTAMP: c_int = 29;
6060
pub const SO_TYPE: c_int = 3;
6161
pub const SO_BUSY_POLL: c_int = 46;
62+
#[cfg(target_os = "linux")]
63+
pub const SO_ORIGINAL_DST: c_int = 80;
6264

6365
// Socket options for TCP sockets
6466
pub const TCP_NODELAY: c_int = 1;

src/sys/socket/sockopt.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use super::{ffi, consts, GetSockOpt, SetSockOpt};
22
use {Errno, Result};
33
use sys::time::TimeVal;
44
use libc::{c_int, uint8_t, c_void, socklen_t};
5+
#[cfg(target_os = "linux")]
6+
use libc::sockaddr_in;
57
use std::mem;
68
use std::os::unix::io::RawFd;
79

@@ -168,6 +170,8 @@ sockopt_impl!(GetOnly, SockType, consts::SOL_SOCKET, consts::SO_TYPE, super::Soc
168170
target_os = "linux",
169171
target_os = "nacl"))]
170172
sockopt_impl!(GetOnly, AcceptConn, consts::SOL_SOCKET, consts::SO_ACCEPTCONN, bool);
173+
#[cfg(target_os = "linux")]
174+
sockopt_impl!(GetOnly, OriginalDst, consts::SOL_IP, consts::SO_ORIGINAL_DST, sockaddr_in);
171175

172176
/*
173177
*

0 commit comments

Comments
 (0)