-
Notifications
You must be signed in to change notification settings - Fork 256
Add a SockAddr type #2
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
Conversation
We don't want to be stuck only supporting IP sockets
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.
👍 looks like exactly what I envisioned
Want to add a to_socket_addr
method as well to convert to libstd? A follow-up can add a unix-specific conversion to the unix socket paths as well.
return None; | ||
} | ||
|
||
Some(mem::transmute_copy(&self.storage)) |
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.
One day this may bite us, but let's hope it's way far away!
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.
I was somewhat terrified when I saw that this was how the addr2raw
function was implemented as well, but it works.
|
||
/// Returns this address as a `SocketAddrV4` if it is in the `AF_INET` | ||
/// family. | ||
pub fn as_inet(&self) -> Option<SocketAddrV4> { |
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.
Perhaps this could return &SocketAddrV4
instead? (a relatively large struct to copy as we go down)
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.
That will lock us into guaranteeing that SocketAddrV4
has the same representation as sockaddr_in
, but if that's okay then sure.
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.
Oh wait good point, let's not do that.
impl From<SocketAddrV4> for SockAddr { | ||
fn from(addr: SocketAddrV4) -> SockAddr { | ||
unsafe { | ||
SockAddr::from_raw_parts(&addr as *const _ as *const _, |
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.
Could this throw in some assert_eq!
about the size of SocketAddrV4
? (same for v6 below)
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.
Done via transmute
to check statically.
|
Ok, let's stick with it as-is and fix up ergonomics as we see fit. Thanks again! (if you'd like a publish of this just lemme know) |
Er actually, added you as collaborator + crate owner, feel free to publish if you need it! (just don't forget to bump the version) |
Thanks! |
We don't want to be stuck only supporting IP sockets