summaryrefslogtreecommitdiff
path: root/src/sys/socket/addr.rs
AgeCommit message (Collapse)Author
2023-07-17More PR feedbackJarred Allen
2023-05-22PR suggestion: Set the length later instead of using `from_raw`Jarred Allen
2023-05-19Set the length of a sockaddr received on LinuxJarred Allen
2023-03-13Enable socket on redoxNoa
2023-01-13Fix endian swap on SocketAddrV6.Aaron Drew
flowinfo and scope_id should not be byte swapped.
2022-12-04Fix clippy lintsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04More annoying formatting changesAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-03Nuke deprecated net APIsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-29Add routing socket typeEmils
2022-11-21Use the new UnixAddr::new_unnamed in the unit testsAlan Somers
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.
2022-11-21Merge #1857bors[bot]
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>
2022-11-21Merge #1871bors[bot]
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>
2022-11-21fixup! Added better support for unnamed unix socket addrsSteven Engler
Make Linux-only
2022-11-21Added better support for unnamed unix socket addrsSteven Engler
2022-11-19Misc internal optimizationsAlan Somers
* Make ipv4addr_to_libc const * Use mem::transmute in ipv4addr_to_libc and ipv6addr_to_libc Fixes #1687 Fixes #1688
2022-11-19Fix using SockaddrStorage to store Unix domain addresses on LinuxAlan Somers
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
2022-11-06Reformat everythingAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-08Fix clippy warnings on nightlyRyan Zoeller
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.
2022-08-14Raise the MSRV to 1.56.1 in anticipation of the next releaseAlan Somers
And fix some documentation lints warned about by the newer rustdoc.
2022-07-23Fix SockaddrLike::from_raw with unaligned inputsAlan Somers
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
2022-06-07Fix socket address family check for SysControlAddr::from_raw.Andrew Walbran
2022-06-07Fix socket address family check for VsockAddr::from_raw.Andrew Walbran
2022-05-31Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux.Alan Somers
This was an oversight from #1684. Fixes #1728
2022-05-14add haiku supportAl Hoang
* enabled as much functionality and defines that match updated libc definitions for haiku
2022-05-02Restore conversions from ip v4/6 Sockaddr types to std::net equivalents.Kyle Huey
Fixes #1710
2022-04-22Fix UnixAddr::size on Linux and AndroidAlan Somers
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.
2022-03-24Merge #1686bors[bot]
1686: [skip ci] better docs for SockaddrLike::from_raw r=asomers a=asomers Fixes #1680 Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-22[skip ci] better docs for SockaddrLike::from_rawAlan Somers
Fixes #1680
2022-03-22Deprecate IpAddr, Ipv4Addr, and Ipv6AddrAlan Somers
Because they're redundant with types in the standard library. Fixes #1681
2022-03-21Replace the Sockaddr enum with a unionAlan Somers
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
2022-03-13Use the same signature for LinkAddr::addr on all platformsAlan Somers
This should've been done as part of #1675
2022-03-13Fix a panic in Linkaddr::addrAlan Somers
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.
2022-01-24uclibc supportJonah Petri
2022-01-23InetAddr::from_std should set sin_len/sin6_len on the BSDsRyan Zoeller
2021-12-30Optimize UnixAddr for the BSDsAlan Somers
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.
2021-12-21UnixAddr: replace path_len with sun_lenAlan Somers
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.
2021-12-21Improve the sockaddr interface:Alan Somers
* 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.
2021-12-20feature-gate most Nix functionsVincent Dagonneau
Using features reduces build time and size for consumer crates. By default all features are enabled.
2021-09-28Revert "Expose SockAddr::from_raw_sockaddr"Alan Somers
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.
2021-09-19Clippy cleanupAlan Somers
And this time, start running Clippy in CI
2021-08-29Rework UnixAddr to fix soundness issuesNoa
2021-08-22Merge #1447bors[bot]
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>
2021-08-21Expose SockAddr::from_raw_sockaddrNoah
2021-08-21Deprecate SockAddr/InetAddr::to_strNoah
2021-08-13constify more functionsAlan Somers
Constify more functions, since we're raising the MSRV from 1.41.0 to 1.46.0. Fixes #1477
2021-07-29Merge #1473 #1474 #1476bors[bot]
1473: sys/stat: add a safe wrapper for mknodat(2) r=asomers a=lucab This introduces a new `mknodat` helper. Ref: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html 1474: Mark most C-derived enums as non_exhaustive r=asomers a=asomers Since libc may add new variants at any time, Nix's consumers should not use exhaustive match patterns. Fixes #1182 1476: Constify many functions r=asomers a=asomers Constify most functions that can be constified. The exceptions are mostly accessors for structs that have no const constructor. Co-authored-by: Luca BRUNO <luca.bruno@coreos.com> Co-authored-by: Alan Somers <asomers@gmail.com>
2021-07-24Constify many functionsAlan Somers
Constify most functions that can be constified. The exceptions are mostly accessors for structs that have no const constructor.
2021-07-24Mark most C-derived enums as non_exhaustiveAlan Somers
Since libc may add new variants at any time, Nix's consumers should not use exhaustive match patterns. Fixes #1182
2021-07-07Overhaul Nix's error typesAlan Somers
For many of Nix's consumers it be convenient to easily convert a Nix error into a std::io::Error. That's currently not possible because of the InvalidPath, InvalidUtf8, and UnsupportedOperation types that have no equivalent in std::io::Error. However, very few of Nix's public APIs actually return those unusual errors. So a more useful API would be for Nix's standard error type to implement Into<std::io::Error>. This commit makes Error a simple NewType around Errno. For most functions it's a drop-in replacement. There are only three exceptions: * clearenv now returns a bespoke error type. It was the only Nix function whose error couldn't be cleanly mapped onto an Errno. * sys::signal::signal now returns Error(Errno::ENOTSUP) instead of Error::UnsupportedOperation when the user passes an incompatible argument to `handler`. * When a NixPath exceeds PATH_MAX, it will now return Error(Errno::ENAMETOOLONG) instead of Error::InvalidPath. In the latter two cases there is now some abiguity about whether the error code was generated by Nix or by the OS. But I think the ambiguity is worth it for the sake of being able to implement Into<io::Error>. This commit also introduces Error::Sys() as a migration aid. Previously that as an enum variant. Now it's a function, but it will work in many of the same contexts as the original. Fixes #1155
2021-05-13Use https instead of httpRyan Zoeller