Age | Commit message (Collapse) | Author |
|
|
|
Co-authored-by: Alan Somers <asomers@gmail.com>
|
|
|
|
|
|
|
|
Rust's standard library no longer guarantees that Ipv4Addr and Ipv6Addr
are wrappers around the C types (though for now at least, they are
identical on all platforms I'm aware of). So do the conversions
explicitly instead of transmuting.
Fixes #2053
|
|
|
|
|
|
|
|
flowinfo and scope_id should not be byte swapped.
|
|
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
|
|
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
|
|
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
|
|
|
|
Use it in the from_sockaddr_un_abstract_unnamed test. That test and
this method were introduced by PRs #1871 and #1857, which crossed each
other.
|
|
1857: Add better support for unnamed unix socket addrs r=asomers a=stevenengler
This adds the following 2 functions/methods: `UnixAddr::new_unnamed` and `UnixAddr::is_unnamed`.
Closes #1585
unix(7) on Linux:
> unnamed: A stream socket that has not been bound to a pathname using bind(2) has no name. Likewise, the two sockets created by socketpair(2) are unnamed. When the address of an unnamed socket is returned, its length is `sizeof(sa_family_t)`, and `sun_path` should not be inspected.
**Edit:** This currently isn't working on BSD, but I see why. Will fix it shortly.
Co-authored-by: Steven Engler <opara@cs.georgetown.edu>
|
|
1871: Fix using SockaddrStorage to store Unix domain addresses on Linux r=rtzoeller a=asomers
Since it has variable length, the user of a sockaddr_un must keep track of its true length. On the BSDs, this is handled by the builtin sun_len field. But on Linux-like operating systems it isn't. Fix this bug by explicitly tracking it for SockaddrStorage just like we already do for UnixAddr.
Fixes #1866
Co-authored-by: Alan Somers <asomers@gmail.com>
|
|
Make Linux-only
|
|
|
|
* Make ipv4addr_to_libc const
* Use mem::transmute in ipv4addr_to_libc and ipv6addr_to_libc
Fixes #1687
Fixes #1688
|
|
Since it has variable length, the user of a sockaddr_un must keep track
of its true length. On the BSDs, this is handled by the builtin sun_len
field. But on Linux-like operating systems it isn't. Fix this bug by
explicitly tracking it for SockaddrStorage just like we already do for
UnixAddr.
Fixes #1866
|
|
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
|
|
Clippy is now smarter about detecting unnecessary casts and
useless conversions, which means we need to be more explicit
about when the conversions are needed for a subset of platforms.
Required changes found by repeatedly running the following command
against a list of the supported platforms.
`xargs -t -I {} sh -c "cargo clippy -Zbuild-std --target {} --all-targets -- -D warnings || exit 255"`
I removed the casts it complained about, and then restored them
with an `#[allow]` if a later target needed the cast.
|
|
And fix some documentation lints warned about by the newer rustdoc.
|
|
The major users of this function are functions like gethostname, which
will always properly align their buffers. But out-of-crate consumers
could manually construct an unaligned buffer. Handle that correctly.
Enable Clippy's cast_ptr_alignment lint. It's disabled by default as it
reports many false positives, but it would've caught this problem.
Reported-by: Miri
Fixes: 1769
|
|
|
|
|
|
This was an oversight from #1684.
Fixes #1728
|
|
* enabled as much functionality and defines that match
updated libc definitions for haiku
|
|
Fixes #1710
|
|
SockaddrLike::size() is meant to return the amount of space that can be
used to store the sockaddr. But on Linux-based OSes, UnixAddr contains
an extra field to store the address's length. This field is not part of
the address, and should not contribute to the value of size().
This bug can't cause an out-of-bounds write, and every OS that we test
on can tolerate the greater-than-expected length, but it might confuse
applications that implement functions similar to getsockname in
userland.
|
|
1686: [skip ci] better docs for SockaddrLike::from_raw r=asomers a=asomers
Fixes #1680
Co-authored-by: Alan Somers <asomers@gmail.com>
|
|
Fixes #1680
|
|
Because they're redundant with types in the standard library.
Fixes #1681
|
|
The SockAddr enum is quite large, and the user must allocate space for
the whole thing even though he usually knows what type he needs.
Furthermore, thanks to the sa_family field, the sockaddr types are
basically an enum even in C.
So replace the ungainly enum with a SockaddrLike trait implemented by
all sockaddr types and a SockaddrStorage union that has safe accessors.
Also, deprecate InetAddr, which only existed to support SockAddr.
Supplants #1504
Fixes #1544
|
|
This should've been done as part of #1675
|
|
The function assumed something about the values of the sockaddr_dl's
fields. But because the inner type is public, we musn't do that. The
only solution is to change the function's signature to return an Option.
|
|
|
|
|
|
On BSD-derived operating systems, struct sockaddr has a sa_len field
that holds the length of the structure. UnixAddr's path_len field is
redundant. Remove path_len on BSD-derived OSes, retaining it only for
Illumos and Linux-based OSes.
Also, ensure that two UnixAddrs compare equal if they differ only by the
presence of a trailing NUL. On Linux, syscalls like getsockname add a
trailing NUL to the sockaddr they return, even if no NUL was present on
the sockaddr originally passed to the kernel via a syscall like bind,
and even though the docs explicitly say that any NUL passed to bind is
not considered to be part of the address. Work around this bug by
stripping it in UnixAddrKind::get(), so that at least two UnixAddrs will
compare identical even if they differ in the presence of a trailing NUL.
|
|
Within UnixAddr, replace the path_len variable (length of the sun_path
field) with sun_len (length of the whole structure). This is more
similar to how other sockaddr types work, and it's the same way that the
BSDs use the sun_len field.
Also, don't require that sun_path be nul-terminated. The OS doesn't
require it.
|
|
* All sockaddr newtypes should be repr(transparent)
* All sockaddr newtypes should be opaque, so the user can't do something
like change the sa_family field in a way that violates invariants.
This is a prerequisite for #1544.
|
|
Using features reduces build time and size for consumer crates. By
default all features are enabled.
|
|
This reverts commit ed43d2c65e65dd68c9cf2dcf06f5ec45a44aaccd.
As discussed in #1544 the API of this function needs to change. For
now, revert the PR that made it public, because it has not yet been
included in any release.
|
|
And this time, start running Clippy in CI
|
|
|
|
1447: Expose SockAddr::from_raw_sockaddr r=asomers a=coolreader18
I also noticed the `SockAddr/InetAddr::to_str` functions were entirely redundant - `ToString` exists for that, & has a blanket impl on `T: Display`.
Co-authored-by: Noah <33094578+coolreader18@users.noreply.github.com>
|
|
|
|
|
|
Constify more functions, since we're raising the MSRV from 1.41.0 to
1.46.0.
Fixes #1477
|