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

Latest version introduces Ipv4 address conversion issues #87

Closed
bltavares opened this issue Jun 25, 2020 · 0 comments · Fixed by #88
Closed

Latest version introduces Ipv4 address conversion issues #87

bltavares opened this issue Jun 25, 2020 · 0 comments · Fixed by #88

Comments

@bltavares
Copy link
Contributor

Hi there,

The latest version published of socket2 (0.3.12) works with the following test program, but when upgrading to latest commit on this repo fails to associate the socket with a multicast address, both on Windows and Linux.

use socket2::{Domain, Protocol, Socket, Type};
use std::net::Ipv4Addr;

fn main() {
    let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))
        .expect("could not create socket");
    socket
        .join_multicast_v4(&Ipv4Addr::new(224, 0, 0, 251), &Ipv4Addr::UNSPECIFIED)
        .expect("could not join multicast group");
}

On Windows it crashes as:

Os { code: 10049, kind: AddrNotAvailable, message: "The requested address is not valid in its context." }

On Linux it crashes as:

Os { code: 22, kind: InvalidInput, message: "Invalid argument" }

Running the test program with git bisect led me to the commit on #68, and maybe there is some conversion errors when sending ip addresses to the system calls.

I will try to take a look there at some point, but I thought of warning to avoid a new release before this is fixed.

bltavares added a commit to bltavares/socket2-rs that referenced this issue Jun 25, 2020
This commit changes the byte order when converting IPv4 Addresses, as
the order was reversed.

The test program used to validate it works was sending a multicast
address to `join_multicast_v4` which was not accepted by either Windows
or Linux. Now the test program compiles and run without issues.

```rust
use socket2::{Domain, Protocol, Socket, Type};
use std::net::Ipv4Addr;

fn main() {
    let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))
        .expect("could not create socket");
    socket
        .join_multicast_v4(&Ipv4Addr::new(224, 0, 0, 251), &Ipv4Addr::UNSPECIFIED)
        .expect("could not join multicast group");
}
```

Fixes rust-lang#87
Thomasdezeeuw pushed a commit that referenced this issue Jun 25, 2020
This commit changes the byte order when converting IPv4 Addresses, as
the order was reversed.

The test program used to validate it works was sending a multicast
address to `join_multicast_v4` which was not accepted by either Windows
or Linux. Now the test program compiles and run without issues.

```rust
use socket2::{Domain, Protocol, Socket, Type};
use std::net::Ipv4Addr;

fn main() {
    let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))
        .expect("could not create socket");
    socket
        .join_multicast_v4(&Ipv4Addr::new(224, 0, 0, 251), &Ipv4Addr::UNSPECIFIED)
        .expect("could not join multicast group");
}
```

Fixes #87
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.

1 participant