Skip to content

Binding to "any" address does not work as expected #1037

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

Closed
chrysn opened this issue Jan 27, 2025 · 2 comments
Closed

Binding to "any" address does not work as expected #1037

chrysn opened this issue Jan 27, 2025 · 2 comments

Comments

@chrysn
Copy link
Contributor

chrysn commented Jan 27, 2025

At least on UDP sockets, calling socket.bind(IpEndpoint::from(core::net::SocketAddr::parse("0.0.0.0:1234").unwrap())) does not behave as expected: It seems to bind not at all, whereas it should bind to that port on any IP address.

There is a workaround of doing socket.bind(1234) -- that's fine when an application calls it directly, but needs a workaround such as

        let bind_to = IpEndpoint::from(local);
        if bind_to.addr.is_unspecified() {
            socket.bind(bind_to.port)?;
        } else {
            socket.bind(bind_to)?;
        }

(And sorry for the IPv4 examples, we're working to have v6 in parallel)

I can most probably provide a PR later; right now, this serves to document the workaround.

chrysn added a commit to chrysn-pull-requests/RIOT-rs that referenced this issue Jan 27, 2025
chrysn added a commit to chrysn-pull-requests/RIOT-rs that referenced this issue Jan 27, 2025
@Dirbaio
Copy link
Member

Dirbaio commented Jan 27, 2025

this is intended behavior, see #981

@chrysn
Copy link
Contributor Author

chrysn commented Jan 27, 2025

Fine with me, sorry for the duplicate.

That's an argument that will also be helpful in rust-embedded-community/embedded-nal#92 -- indicating that the core types are a tad too far on the "POSIX sockets" side of things, with more idiomatic expressions around (esp. when the IP addresses are expressed in such a way that they have a zero niche).

@chrysn chrysn closed this as completed Jan 27, 2025
ROMemories pushed a commit to ROMemories/ariel-os that referenced this issue Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants