summaryrefslogtreecommitdiff
path: root/src/sys/socket
AgeCommit message (Collapse)Author
2020-04-12Remove sys::socket::addr::from_libc_sockaddr from the public APIAlan Somers
This function never should've been public, since it's basically impossible to use directly. It's only public due to an oversight from PR #667 .
2019-12-01ScmCredentials now wraps UnixCredentials instead of libc::ucredAlan Somers
2019-11-30Remove the deprecated CmsgSpaceAlan Somers
This eliminates one of the last remaining uninitialized memory accesses in Nix. Fixes #1142
2019-10-28Fix sys::socket::recvfrom for TCP socketsAlan Somers
recvfrom(2) only returns the sender's address for protocols that provide it. Usually, that means it returns the sender's address for datagram sockets but not for stream sockets. Fixes #1144
2019-10-15Properly initialize msghdr when using muslYuxuan Shui
Because of the use of MaybeUninit::uninit, the padding fields in msghdr, which only present on musl builds, are not initialized. Causing garbage data to be sent to the kernel. This change ensures the paddings are always zeroed.
2019-09-19Where relevant, replace equality checks in assert! with assert_eq!Xavier L'Heureux
`assert_eq!` gives more debug info when the test fails by default than `assert!`. This should help make debugging easier.
2019-09-04Merge #1120bors[bot]
1120: Fix length of abstract socket address r=asomers a=yshui NULL bytes have no special significance in an abstrace address, and the length of the address is solely decided by the length member. If the length is set to sun_path.len(), all the NULL bytes will be considered part of the address. Tests are updated accordingly. Closes #1119 Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com> Co-authored-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-09-04Fix length of abstract socket addressYuxuan Shui
NULL bytes have no special significance in an abstrace address, and the length of the address is solely decided by the length member. If the length is set to sun_path.len(), all the NULL bytes will be considered part of the address. Tests are updated accordingly. Closes #1119 Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
2019-09-03Replace most instances of mem::uninitialized with mem::MaybeUninitAlan Somers
Only two instances remain: * For the deprecated sys::socket::CmsgSpace::new. We should probably just remove that method. * For sys::termios::Termios::default_uninit. This will require some more thought. Fixes #1096
2019-08-29Implement Default for FdSetAlan Somers
2019-08-29Remove an obsolete commentAlan Somers
It was leftover from internal churn during PR #1020.
2019-08-29Clippy: silence a false-positive cast alignment warningAlan Somers
2019-08-29Clippy: remove unnecessary mem::transmuteAlan Somers
2019-08-29Clippy cleanupAlan Somers
2019-07-13Merge #1095bors[bot]
1095: Fix warnings on Rust 1.37.0 r=asomers a=asomers * Replace obsolete range syntax "..." with inclusive range "..=" * Use dyn Trait syntax instead of Box<Trait> * Raise MSRV to 1.27.0 (for dyn Trait syntax) * Test with nightly again Co-authored-by: Alan Somers <asomers@gmail.com>
2019-07-13Fix warnings on Rust 1.37.0Alan Somers
* Replace obsolete range syntax "..." with inclusive range "..=" * Use dyn Trait syntax instead of Box<Trait> * Raise MSRV to 1.27.0 (for dyn Trait syntax) * Raise MSRV to 1.31.0 (because of rand) tempfile pulls in rand, and rand pulls in fuchsia-cprng, which requires 1.31.0. Why rand pulls in fuchsia-cprng I don't know. It's specified as a target-specific dependency, but Cargo tries to build it anyway (only on Linux, not on FreeBSD or OSX). A bug in Cargo 1.27.0?
2019-07-12socket: add support for AF_VSOCKStefano Garzarella
This patch adds AF_VSOCK support to AddressFamily in order to use VSOCK socket. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2019-06-11Fix tests for abstract socketsBryant Mairs
Abstract paths should always be N-1 in length where N is the length of the `sun_path` field (first byte is \0). Given that, `UnixAddr::new_abstract()` should always return this N-1 length, not just the length of the string provided (the rest of the array will be \0s).
2019-06-09Add extra traits for all typesBryant Mairs
Derive Clone, Copy, Eq, Hash, and PartialEq for all types. Not all traits are supported by all types, which is why many are missing some.
2019-06-07socket: expose MSG_WAITALL in MsgFlagsStefano Garzarella
MSG_WAITALL can be useful with recv() to wait the full amount of data requested. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2019-06-06Fix the is_so_mark_functional test in Linux containersAlan Somers
It's not sufficient to check for root privileges. In a container, the euid may be root even though the user lacks some capabilities. Replace this test's root check with a check for the CAP_NET_ADMIN capability instead.
2019-06-03Check euid, not uid, for socket testsAlan Somers
2019-05-31fix more uintXY_t instancesJohannes Schilling
2019-05-31libc::uint8_t deprecated in favor of rust u8Johannes Schilling
2019-04-29Restored the bytes field on RecvMsg in order to know the amount of bytes ↵Vincent Dagonneau
received using recvmsg.
2019-04-09Uncomment to_std and from_std methods for IpAddrrabbott99
2019-03-12Support AF_ALGGleb Pomykalov
2019-02-14Enable IPv4PacketInfo and Ipv6PacketInfo on more OSes.Alan Somers
This was an oversight from PR #1002
2019-02-14Fix misaligned references when using recvmsg with control messagesAlan Somers
On some platforms the alignment of cmsg_data could be less than the alignment of the messages that it contains. That led to unaligned reads on those platforms. This change fixes the issue by always copying the message contents into aligned objects. The change is not 100% backwards compatible when using recvmsg. Users may have to replace code like this: ```rust if let ControlMessage::ScmRights(&fds) = cmsg { ``` with this: ```rust if let ControlMessageOwned::ScmRights(fds) = cmsg { ``` Fixes #999
2019-02-14Replace CmsgSpace with a macroAlan Somers
CmsgSpace had three problems: 1) It would oversize buffers that expect multiple control messages 2) It didn't use the libc CMSG_SPACE(3) macro, so it might actually undersize a buffer for a single control message. 3) It could do bad things on drop, if you instantiate it with a type that implements Drop (which none of the currently supported ControlMessage types do). Fixes #994
2019-02-14Fix error handling of RecvMsgAlan Somers
There were two problems: 1) It would always return Ok, even on error 2) It could panic if there was an error, because sockaddr_storage_to_addr would be called on uninitialized memory.
2019-02-14Replace hand-rolled cmsg logic with libc's cmsg(3) functions.Alan Somers
Our hand-rolled logic had subtle alignment bugs that caused test_scm_rights to fail on OpenBSD (and probably could cause problems on other platforms too). Using cmsg(3) is much cleaner, shorter, and more portable. No user-visible changes.
2019-01-23Add IP_RECVIF & IP_RECVDSTADDR.Tom Pusateri
Include IP_PKTINFO and IP6_PKTINFO on netbsd/openbsd.
2019-01-06Make ScmTimestamp's doc test more robustAlan Somers
The old test made assumptions about the responsiveness of the test environment. The new test does not, and it's simpler too.
2018-12-17Merge #993bors[bot]
993: Don't reference packed structs. r=asomers a=pusateri Fixes #992. Don't merge this yet. I have more testing to do. I just am pushing it up for others. Co-authored-by: Tom Pusateri <pusateri@bangj.com>
2018-12-17Merge #990bors[bot]
990: Add cmsg PKTINFO for IPv4 and IPv6. r=asomers a=pusateri Replaces #891 and attempts to address all previous concerns. Co-authored-by: Tom Pusateri <pusateri@bangj.com>
2018-12-16Allow 'cargo test' to complete successfully on NetBSD 8.0.Tom Pusateri
Some tests have been disabled and will need further review.
2018-12-15Add cmsg PKTINFO for IPv4 and IPv6.Tom Pusateri
ignore pktinfo tests on qemu mips,mips64,powerpc64 Original work by @mcginty.
2018-12-08Replace try! with ?Alan Somers
try! is not available in Rust 2018
2018-12-06Add support of TCP_CONGESTION for setsockoptFensteer
2018-11-09Add example for setsockoptPovilas Balciunas
Makes it easier for newcomers :)
2018-10-15socket: add AF_UNSPEC to AddressFamilyLevente Kurusa
Signed-off-by: Levente Kurusa <lkurusa@acm.org>
2018-08-15sendmsg: remove unneeded mutIgor Gnatenko
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
2018-07-27Fix *decoding* of cmsgs and add `ScmCredentials`.Jonas Schievink
2018-07-05Merge #921bors[bot]
921: Get `SO_PEERCRED` working on all Linux targets r=asomers a=jonas-schievink These were disabled for ARM way back in 0db6ed1a28b4fb4d408cd9b7c4dba0a79bccf1f7 and 09c00ed7d9d92db2a79baa3ed212e7e239edceb9. Try to enable them for all arches and Android as well, since the removal wasn't really explained and I see no reason why this shouldn't work. Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2018-07-05Get `SO_PEERCRED` working on all Linux targetsJonas Schievink
2018-07-04Clean up cmsg code and fix passing multiple cmsgsalecmocatta
2018-06-01Remove emulation of FD_CLOEXEC/O_NONBLOCKBryant Mairs
Rather than using the native implementation of these constants on supported platforms, the native implementation was instead emulated. This was also hidden from the user even though this could result in data races and the functionality being broken. Native functionality is, however, not support on macos/ios. Rather than enable this emulation solely for this platform, it should be removed as this is a dangerous abstraction.
2018-05-28Fix bind() on Android 64-bitBryant Mairs
libc fixed `bind()` for Android 64-bit targets, so change our code to match.
2018-05-22TypoXavier Bestel