diff --git a/src/dox.rs b/src/dox.rs index c7d3dc9c2deba..762212607f3af 100644 --- a/src/dox.rs +++ b/src/dox.rs @@ -6,6 +6,7 @@ mod imp { pub use core::clone::Clone; pub use core::marker::Copy; pub use core::mem; + pub use core::hash::{Hash, Hasher}; } #[cfg(dox)] diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index e8f97e4edeb08..ff1772a821d40 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -173,6 +173,7 @@ s! { pub dli_saddr: *mut ::c_void, } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in { pub sin_len: u8, pub sin_family: ::sa_family_t, diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 4b3a504dcbfbf..29c38939bdf5d 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -113,6 +113,7 @@ s! { pub dli_saddr: *mut ::c_void, } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in { pub sin_len: u8, pub sin_family: ::sa_family_t, diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 027033bcec963..88dc67a22c9cd 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -1,3 +1,4 @@ +use dox::{Hash, Hasher}; use dox::mem; pub type c_char = i8; @@ -11,12 +12,14 @@ pub type pthread_t = ::uintptr_t; pub type nfds_t = ::c_uint; s! { + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr { pub sa_len: u8, pub sa_family: sa_family_t, pub sa_data: [::c_char; 14], } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in6 { pub sin6_len: u8, pub sin6_family: sa_family_t, @@ -107,6 +110,21 @@ s! { } } +impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family && &self.sun_path[..] == &other.sun_path[..] + } +} + +impl Eq for sockaddr_un { } + +impl Hash for sockaddr_un { + fn hash(&self, state: &mut H) where H: Hasher { + self.sun_family.hash(state); + &self.sun_path[..].hash(state); + } +} + pub const FIOCLEX: ::c_ulong = 0x20006601; pub const FIONBIO: ::c_ulong = 0x8004667e; diff --git a/src/unix/bsd/openbsdlike/mod.rs b/src/unix/bsd/openbsdlike/mod.rs index d4319b2d56294..daa1504d02e10 100644 --- a/src/unix/bsd/openbsdlike/mod.rs +++ b/src/unix/bsd/openbsdlike/mod.rs @@ -24,6 +24,7 @@ s! { pub ss_flags: ::c_int, } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in { pub sin_len: u8, pub sin_family: ::sa_family_t, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 704406e63120f..8358fccec7e72 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -57,10 +57,12 @@ s! { } #[cfg_attr(target_os = "netbsd", repr(packed))] + #[derive(Eq, Hash, PartialEq)] pub struct in_addr { pub s_addr: in_addr_t, } + #[derive(Eq, Hash, PartialEq)] pub struct in6_addr { pub s6_addr: [u8; 16], __align: [u32; 0], diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index e8dec9c68e9a8..7e9418822a59b 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -125,6 +125,7 @@ s! { __f_spare: [::c_int; 6], } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_nl { pub nl_family: ::sa_family_t, nl_pad: ::c_ushort, diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 6c93a0ddcf0c3..54fbd65bb64af 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -1,3 +1,4 @@ +use dox::{Hash, Hasher}; use dox::mem; pub type rlim_t = c_ulong; @@ -9,11 +10,13 @@ pub type tcflag_t = ::c_uint; pub enum timezone {} s! { + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr { pub sa_family: sa_family_t, pub sa_data: [::c_char; 14], } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in { pub sin_family: sa_family_t, pub sin_port: ::in_port_t, @@ -21,6 +24,7 @@ s! { pub sin_zero: [u8; 8], } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in6 { pub sin6_family: sa_family_t, pub sin6_port: ::in_port_t, @@ -61,6 +65,7 @@ s! { pub ai_next: *mut addrinfo, } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_ll { pub sll_family: ::c_ushort, pub sll_protocol: ::c_ushort, @@ -125,6 +130,21 @@ s! { } } +impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family && &self.sun_path[..] == &other.sun_path[..] + } +} + +impl Eq for sockaddr_un { } + +impl Hash for sockaddr_un { + fn hash(&self, state: &mut H) where H: Hasher { + self.sun_family.hash(state); + &self.sun_path[..].hash(state); + } +} + // intentionally not public, only used for fd_set #[cfg(target_pointer_width = "32")] const ULONG_SIZE: usize = 32; diff --git a/src/unix/sunos/mod.rs b/src/unix/sunos/mod.rs index 733709c7971c3..17efb96b716b3 100644 --- a/src/unix/sunos/mod.rs +++ b/src/unix/sunos/mod.rs @@ -1,3 +1,5 @@ +use dox::{Hash, Hasher}; + pub type c_char = i8; pub type c_long = i64; pub type c_ulong = u64; @@ -34,11 +36,13 @@ pub type fflags_t = u32; pub enum timezone {} s! { + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr { pub sa_family: sa_family_t, pub sa_data: [::c_char; 14], } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in { pub sin_family: sa_family_t, pub sin_port: ::in_port_t, @@ -46,6 +50,7 @@ s! { pub sin_zero: [::c_char; 8] } + #[derive(Eq, Hash, PartialEq)] pub struct sockaddr_in6 { pub sin6_family: sa_family_t, pub sin6_port: ::in_port_t, @@ -273,6 +278,21 @@ s! { } } +impl PartialEq for sockaddr_un { + fn eq(&self, other: &sockaddr_un) -> bool { + self.sun_family == other.sun_family && &self.sun_path[..] == &other.sun_path[..] + } +} + +impl Eq for sockaddr_un { } + +impl Hash for sockaddr_un { + fn hash(&self, state: &mut H) where H: Hasher { + self.sun_family.hash(state); + &self.sun_path[..].hash(state); + } +} + pub const SA_ONSTACK: ::c_int = 0x00000001; pub const SA_RESETHAND: ::c_int = 0x00000002; pub const SA_RESTART: ::c_int = 0x00000004;