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

Local interface/ip #15

Closed
martinthomson opened this issue Sep 3, 2024 · 2 comments · Fixed by #16
Closed

Local interface/ip #15

martinthomson opened this issue Sep 3, 2024 · 2 comments · Fixed by #16

Comments

@martinthomson
Copy link
Member

The interface uses a remote address only. UdpSocket::bind takes a local address, which is presently unspecified. A more general approach would be to specify the local address in addition to the remote address.

@larseggert
Copy link
Collaborator

Good idea. If a local address is passed in, that would preclude the need to connect the socket, since the binding already establishes which interface will be used.

Do you see this as one call, where either local or remote can be unspecified? Or two calls?

@martinthomson
Copy link
Member Author

¯\_(ツ)_/¯

It's a hard one. You could make the interface take a new enum type something like this:

enum SocketAddresses {
  Local(SocketAddr),
  Remote(SocketAddr),
  Both((SocketAddr, SocketAddr)),
}

impl From<(SocketAddr, SocketAddr)> for SocketAddresses { ... }
impl From<(Option<SocketAddr>, SocketAddr)> for SocketAddresses { ... }
impl From<(SocketAddr, Option<SocketAddr>)> for SocketAddresses { ... }
// I don't know if UdpSocket::connect works with a remote port of 0, but you could try each of these...
impl From<(IpAddr, IpAddr)> for SocketAddresses { ... } // Uses port = 0
impl From<(IpAddr, Option<IpAddr>)> for SocketAddresses { ... }
impl From<(Option<IpAddr>, IpAddr)> for SocketAddresses { ... }

pub fn interface_mtu<A>(addrs: A)
  where SocketAddresses: From<A> { ... }

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 a pull request may close this issue.

2 participants