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

Impossible to construct an in6_addr #58

Closed
mrmonday opened this issue Nov 11, 2015 · 3 comments
Closed

Impossible to construct an in6_addr #58

mrmonday opened this issue Nov 11, 2015 · 3 comments

Comments

@mrmonday
Copy link

The new definition of in6_addr:

pub struct in6_addr {
    pub s6_addr: [u8; 16],
    __align: [u32; 0],
}

Link: https://github.com/rust-lang-nursery/libc/blob/e7ff66ba3df6eb0d10953245a2a6fd2ecf082ccd/src/unix/mod.rs#L62

Means that it is now impossible to construct a value of type in6_addr from Rust, outside of the libc crate, since the __align field is private. I've had to fix libpnet to an old version of libc to work around this.

mrmonday added a commit to mrmonday/libpnet that referenced this issue Nov 11, 2015
This fixes libpnet to an older version of libc, until this is fixed.
homu added a commit to libpnet/libpnet that referenced this issue Nov 11, 2015
Workaround rust-lang/libc#58.

This fixes libpnet to an older version of libc, until this is fixed.

See also: rust-lang/libc#58.
@alexcrichton
Copy link
Member

Thanks for the report! This has also been reported here and here, and unfortunately this is just a place where Rust doesn't handle FFI unions very well right now. The underlying type is a union which gains it higher alignment but the exposed fields right now don't give us that alignment. When we have custom alignment we may be able to get around this via other means, but for now you can construct this like you would in C:

let mut foo: libc::in6_addr = mem::uninitialized();
// initialize foo.s6_addr
return foo

Which is to say it's not necessarily "impossible", just not very idiomatic!

@mrmonday
Copy link
Author

Thanks you. Sorry for the noise, I didn't find those issues when I searched for some reason.

@ghost
Copy link

ghost commented May 23, 2018

It should be possible to replace __align with #[repr(C, align(4))] now. Or am I wrong here?

Edit turns out I am:
<sfackler> sebk: that will bump the minimum supported rust version

tgross35 pushed a commit to tgross35/rust-libc that referenced this issue Feb 22, 2025
Add C++ support and support renaming consts
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

2 participants