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 SO_ORIGINAL_DST #367

Merged
merged 1 commit into from
May 3, 2016
Merged

Add SO_ORIGINAL_DST #367

merged 1 commit into from
May 3, 2016

Conversation

justinlatimer
Copy link
Contributor

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!

@@ -1,7 +1,7 @@
use super::{ffi, consts, GetSockOpt, SetSockOpt};
use {Errno, Result};
use sys::time::TimeVal;
use libc::{c_int, uint8_t, c_void, socklen_t};
use libc::{c_int, uint8_t, c_void, socklen_t, sockaddr_in};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a conditional use only for linux (see Travis-CI result).

@fiveop
Copy link
Contributor

fiveop commented May 2, 2016

When you fix the use error on apple, we can merge this.

@justinlatimer
Copy link
Contributor Author

@fiveop Updated to fix the apple error, thanks!

@@ -2,6 +2,8 @@ use super::{ffi, consts, GetSockOpt, SetSockOpt};
use {Errno, Result};
use sys::time::TimeVal;
use libc::{c_int, uint8_t, c_void, socklen_t};
#[cfg(target_os = "linux")]
use libc::{sockaddr_in};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny nit: no need for braces if there's just a single name imported

@justinlatimer
Copy link
Contributor Author

@kamalmarhubi braces removed, thanks!

@kamalmarhubi
Copy link
Member

@justinlatimer yay thanks! could you squash down to a single commit, and we'll get this merged :-)

@justinlatimer
Copy link
Contributor Author

@kamalmarhubi all squashed, thanks!

@kamalmarhubi
Copy link
Member

yay!

@homu r+ 3954580

@homu homu merged commit 3954580 into nix-rust:master May 3, 2016
homu added a commit that referenced this pull request May 3, 2016
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!
@justinlatimer justinlatimer deleted the so-original-dst branch May 3, 2016 01:14
@sorz
Copy link

sorz commented Aug 5, 2018

Should this return sockaddr instead of sockaddr_in for compatible with IPv6?

EDIT: or a SOL_IPV6 separately? Sorry, I'm not familiar with these APIs.

@asomers
Copy link
Member

asomers commented Aug 5, 2018

@sorz I can't find any documentation on SO_ORIGINAL_DST anywhere. I see another symbol defined named IP6T_SO_ORIGINAL_DST, but I don't know exactly what either does. You'll need to dive into the Linux source, I'm afraid, if you want to find out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants