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

Determine the primary outbound local IP if multiple present in interfaces #94

Open
jakewilliami opened this issue Nov 28, 2022 · 1 comment

Comments

@jakewilliami
Copy link
Contributor

It may occur that multiple local IP addresses are present, however as of #95 (at least for the BSD implementation), this library will find the first non-loopback local IP. I think we should modify this to determine the primary outbound local IP.

@jakewilliami
Copy link
Contributor Author

POC:

pub fn local_ip() -> Result<IpAddr, std::io::Error> {
    let sock_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), 80);
    let socket = UdpSocket::bind("0.0.0.0:0").expect("Could not bind to address");
    match socket.connect(sock_addr) {
        Ok(_) => Ok(socket.local_addr().unwrap().ip()),
        Err(e) => Err(e),
    }
}

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

No branches or pull requests

1 participant