Skip to content

Commit

Permalink
Merge #1642
Browse files Browse the repository at this point in the history
1642: InetAddr::from_std should set sin_len/sin6_len on the BSDs r=asomers a=rtzoeller

Resolves #1246.

Co-authored-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
  • Loading branch information
bors[bot] and rtzoeller committed Jan 23, 2022
2 parents 4c3001b + ad7e3c7 commit ae2b7b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(#[1639](https://github.com/nix-rust/nix/pull/1639))

### Fixed

- `InetAddr::from_std` now sets the `sin_len`/`sin6_len` fields on the BSDs.
(#[1642](https://github.com/nix-rust/nix/pull/1642))

### Removed

- Removed public access to the inner fields of `NetlinkAddr`, `AlgAddr`,
Expand Down
10 changes: 10 additions & 0 deletions src/sys/socket/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ impl InetAddr {
match *std {
net::SocketAddr::V4(ref addr) => {
InetAddr::V4(libc::sockaddr_in {
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
target_os = "haiku", target_os = "hermit",
target_os = "ios", target_os = "macos",
target_os = "netbsd", target_os = "openbsd"))]
sin_len: mem::size_of::<libc::sockaddr_in>() as u8,
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,
Expand All @@ -338,6 +343,11 @@ impl InetAddr {
}
net::SocketAddr::V6(ref addr) => {
InetAddr::V6(libc::sockaddr_in6 {
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
target_os = "haiku", target_os = "hermit",
target_os = "ios", target_os = "macos",
target_os = "netbsd", target_os = "openbsd"))]
sin6_len: mem::size_of::<libc::sockaddr_in6>() as u8,
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,
Expand Down

0 comments on commit ae2b7b3

Please sign in to comment.