summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorKamal Marhubi <kamal@marhubi.com>2016-03-29 19:32:21 -0400
committerKamal Marhubi <kamal@marhubi.com>2016-03-30 14:20:02 -0400
commit6d01a26510cd66aba61dea5e4988bc21d06496aa (patch)
tree9759c9558c66e07e80383ae9a4bf56beb7b3fdf1 /src/sys
parenta09d07b856ccce843c9e0d9ef4da8d6c09d26e48 (diff)
downloadnix-6d01a26510cd66aba61dea5e4988bc21d06496aa.zip
socket: Respect IPv6 flowinfo and scope_id in InetAddr::from_std
Fixes #329
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/socket/addr.rs26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 32210891..4854517f 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -36,12 +36,26 @@ pub enum InetAddr {
impl InetAddr {
pub fn from_std(std: &net::SocketAddr) -> InetAddr {
- let ip = match *std {
- net::SocketAddr::V4(ref addr) => IpAddr::V4(Ipv4Addr::from_std(&addr.ip())),
- net::SocketAddr::V6(ref addr) => IpAddr::V6(Ipv6Addr::from_std(&addr.ip())),
- };
-
- InetAddr::new(ip, std.port())
+ match *std {
+ net::SocketAddr::V4(ref addr) => {
+ InetAddr::V4(libc::sockaddr_in {
+ sin_family: AddressFamily::Inet as sa_family_t,
+ sin_port: addr.port().to_be(), // network byte order
+ sin_addr: Ipv4Addr::from_std(addr.ip()).0,
+ .. unsafe { mem::zeroed() }
+ })
+ }
+ net::SocketAddr::V6(ref addr) => {
+ InetAddr::V6(libc::sockaddr_in6 {
+ sin6_family: AddressFamily::Inet6 as sa_family_t,
+ sin6_port: addr.port().to_be(), // network byte order
+ sin6_addr: Ipv6Addr::from_std(addr.ip()).0,
+ sin6_flowinfo: addr.flowinfo(), // host byte order
+ sin6_scope_id: addr.scope_id(), // host byte order
+ .. unsafe { mem::zeroed() }
+ })
+ }
+ }
}
pub fn new(ip: IpAddr, port: u16) -> InetAddr {