-
Notifications
You must be signed in to change notification settings - Fork 677
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
Modified return type for ipaddr #2151
Modified return type for ipaddr #2151
Conversation
Signed-off-by: carlosb1 <[email protected]>
Signed-off-by: carlosb1 <[email protected]>
Signed-off-by: carlosb1 <[email protected]>
Signed-off-by: carlosb1 <[email protected]>
src/sys/socket/addr.rs
Outdated
@@ -1006,8 +1006,8 @@ pub struct SockaddrIn(libc::sockaddr_in); | |||
impl SockaddrIn { | |||
/// Returns the IP address associated with this socket address, in native | |||
/// endian. | |||
pub const fn ip(&self) -> libc::in_addr_t { | |||
u32::from_be(self.0.sin_addr.s_addr) | |||
pub fn ip(&self) -> net::Ipv4Addr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we can also retain the const
here if we choose the following impl:
pub const fn ip(&self) -> Ipv4Addr {
let bytes = self.0.sin_addr.s_addr.to_ne_bytes();
let (a, b, c, d) = (bytes[0], bytes[1], bytes[2], bytes[3]);
Ipv4Addr::new(a, b, c, d)
}
And for pub const fn ip(&self) -> Ipv6Addr {
let bytes = self.0.sin6_addr.s6_addr;
let [a, b, c, d, e, f, g, h] =
unsafe { transmute::<_, [u16; 8]>(bytes) };
// Ipv6Addr::new() takes segments in native endian, convert them here
let [a, b, c, d, e, f, g, h] = [
u16::from_be(a),
u16::from_be(b),
u16::from_be(c),
u16::from_be(d),
u16::from_be(e),
u16::from_be(f),
u16::from_be(g),
u16::from_be(h),
];
Ipv6Addr::new(a, b, c, d, e, f, g, h)
} |
f8213aa
to
870459f
Compare
Signed-off-by: carlosb1 <[email protected]>
|
Signed-off-by: carlosb1 <[email protected]>
Signed-off-by: carlosb1 <[email protected]>
I reimplemented it |
LGTM! Sorry for the late review, thanks for doing this! |
I forgot to mention that we have changed the CHANGELOG mode in #2149, let me fix this later |
What does this PR do
Fixes #2003
Checklist:
CONTRIBUTING.md