| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 2 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::IoSliceMutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSliceMut#, |
| 3 | osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::{AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#, RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#}, |
| 4 | }; |
| 5 | |
| 6 | use libcrust-analyzer cargo libc 0.2.152 crate/::{c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, sockaddrrust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr#, sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#}; |
| 7 | |
| 8 | use craterust-analyzer cargo timestamped-socket 0.2.2 crate/::{ |
| 9 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr()., |
| 10 | control_messagerust-analyzer cargo timestamped-socket 0.2.2 control_message/::{ |
| 11 | empty_msghdrrust-analyzer cargo timestamped-socket 0.2.2 control_message/empty_msghdr()., zeroed_sockaddr_storagerust-analyzer cargo timestamped-socket 0.2.2 control_message/zeroed_sockaddr_storage()., ControlMessagerust-analyzer cargo timestamped-socket 0.2.2 control_message/ControlMessage#, ControlMessageIteratorrust-analyzer cargo timestamped-socket 0.2.2 control_message/ControlMessageIterator#, MessageQueuerust-analyzer cargo timestamped-socket 0.2.2 control_message/MessageQueue#, |
| 12 | }, |
| 13 | }; |
| 14 | |
| 15 | #[cfg(target_os = "freebsd")] |
| 16 | mod freebsd; |
| 17 | #[cfg(target_os = "linux")] |
| 18 | mod linuxrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/linux/; |
| 19 | #[cfg(target_os = "macos")] |
| 20 | mod macos; |
| 21 | |
| 22 | // A struct providing safe wrappers around various socket api calls |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 24 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) struct RawSocketrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket# { |
| 25 | fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd.: RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd#, |
| 26 | } |
| 27 | |
| 28 | impl AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd# for RawSocketrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket# { |
| 29 | fn as_raw_fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket][AsRawFd]as_raw_fd().(&self) -> RawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/RawFd# { |
| 30 | self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd. |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | impl RawSocketrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket# { |
| 35 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn openrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]open().( |
| 36 | domain: libcrust-analyzer cargo libc 0.2.152 crate/::c_intrust-analyzer cargo libc 0.2.152 unix/c_int#, |
| 37 | ty: libcrust-analyzer cargo libc 0.2.152 crate/::c_intrust-analyzer cargo libc 0.2.152 unix/c_int#, |
| 38 | protocol: libcrust-analyzer cargo libc 0.2.152 crate/::c_intrust-analyzer cargo libc 0.2.152 unix/c_int#, |
| 39 | ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<Selfrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]> { |
| 40 | // Safety: libc::socket is always safe to call |
| 41 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(RawSocketrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket# { |
| 42 | fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd.: cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::socketrust-analyzer cargo libc 0.2.152 socket().(domain, ty, protocol) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 43 | }) |
| 44 | } |
| 45 | |
| 46 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn bindrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]bind().(&self, addr: sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 47 | // Per posix, it may be invalid to specify a length larger than that of the family. |
| 48 | let len = sockaddr_lenrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/sockaddr_len().(addr); |
| 49 | |
| 50 | // Safety: socket is valid for the duration of the call, addr lives for the duration of |
| 51 | // the call and len is at most the length of addr. |
| 52 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::bindrust-analyzer cargo libc 0.2.152 bind().(self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., &addr as *const _ as *const _, len) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 53 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 54 | } |
| 55 | |
| 56 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn connectrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]connect().(&self, addr: sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 57 | // Per posix, it may be invalid to specify a length larger than that of the family. |
| 58 | let len = sockaddr_lenrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/sockaddr_len().(addr); |
| 59 | |
| 60 | // Safety: socket is valid for the duration of the call, addr lives for the duration of |
| 61 | // the call and len is at most the length of addr. |
| 62 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::connectrust-analyzer cargo libc 0.2.152 connect().(self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., &addr as *const _ as *const _, len) })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 63 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 64 | } |
| 65 | |
| 66 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn set_nonblockingrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]set_nonblocking().(&self, nonblocking: bool) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 67 | let nonblocking = nonblocking as libcrust-analyzer cargo libc 0.2.152 crate/::c_intrust-analyzer cargo libc 0.2.152 unix/c_int#; |
| 68 | // Safety: nonblocking lives for the duration of the call, and is 4 bytes long as expected for FIONBIO |
| 69 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::ioctlrust-analyzer cargo libc 0.2.152 ioctl().(self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., libcrust-analyzer cargo libc 0.2.152 crate/::FIONBIOrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/arch/generic/FIONBIO., &nonblocking) }).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/drop().) |
| 70 | } |
| 71 | |
| 72 | #[cfg(target_os = "linux")] |
| 73 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn reuse_addrrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]reuse_addr().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 74 | let options = 1u32; |
| 75 | |
| 76 | // Safety: |
| 77 | // |
| 78 | // the pointer argument is valid, the size is accurate |
| 79 | unsafe { |
| 80 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(libcrust-analyzer cargo libc 0.2.152 crate/::setsockoptrust-analyzer cargo libc 0.2.152 setsockopt().( |
| 81 | self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., |
| 82 | libcrust-analyzer cargo libc 0.2.152 crate/::SOL_SOCKETrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/arch/generic/SOL_SOCKET., |
| 83 | libcrust-analyzer cargo libc 0.2.152 crate/::SO_REUSEADDRrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/arch/generic/SO_REUSEADDR., |
| 84 | &options as *const _ as *const libcrust-analyzer cargo libc 0.2.152 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, |
| 85 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&options) as libcrust-analyzer cargo libc 0.2.152 crate/::socklen_trust-analyzer cargo libc 0.2.152 unix/linux_like/linux/socklen_t#, |
| 86 | ))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 87 | } |
| 88 | |
| 89 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 90 | } |
| 91 | |
| 92 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn receive_messagerust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]receive_message().<'a>( |
| 93 | &self, |
| 94 | packet_buf: &mut [u8], |
| 95 | control_buf: &'a mut [u8], |
| 96 | queue: MessageQueuerust-analyzer cargo timestamped-socket 0.2.2 control_message/MessageQueue#, |
| 97 | ) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<( |
| 98 | usize, |
| 99 | impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = ControlMessagerust-analyzer cargo timestamped-socket 0.2.2 control_message/ControlMessage#> + 'a, |
| 100 | sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#, |
| 101 | )> { |
| 102 | let mut buf_slice = IoSliceMutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSliceMut#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/impl#[`IoSliceMut<'a>`]new().(packet_buf); |
| 103 | let mut addr = zeroed_sockaddr_storagerust-analyzer cargo timestamped-socket 0.2.2 control_message/zeroed_sockaddr_storage().(); |
| 104 | |
| 105 | let mut mhdr = empty_msghdrrust-analyzer cargo timestamped-socket 0.2.2 control_message/empty_msghdr().(); |
| 106 | |
| 107 | mhdr.msg_controlrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_control. = control_buf.as_mut_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_mut_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<libcrust-analyzer cargo libc 0.2.152 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#>(); |
| 108 | mhdr.msg_controllenrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_controllen. = control_buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as _; |
| 109 | mhdr.msg_iovrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_iov. = (&mut buf_slice as *mut IoSliceMutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/IoSliceMut#).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<libcrust-analyzer cargo libc 0.2.152 crate/::iovecrust-analyzer cargo libc 0.2.152 unix/iovec#>(); |
| 110 | mhdr.msg_iovlenrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_iovlen. = 1; |
| 111 | mhdr.msg_flagsrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_flags. = 0; |
| 112 | mhdr.msg_namerust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_name. = (&mut addr as *mut libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#).castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<libcrust-analyzer cargo libc 0.2.152 crate/::c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#>(); |
| 113 | mhdr.msg_namelenrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_namelen. = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#>() as u32; |
| 114 | |
| 115 | let receive_flags = match queue { |
| 116 | MessageQueuerust-analyzer cargo timestamped-socket 0.2.2 control_message/MessageQueue#::Normalrust-analyzer cargo timestamped-socket 0.2.2 control_message/MessageQueue#Normal# => 0, |
| 117 | #[cfg(target_os = "linux")] |
| 118 | MessageQueuerust-analyzer cargo timestamped-socket 0.2.2 control_message/MessageQueue#::Errorrust-analyzer cargo timestamped-socket 0.2.2 control_message/MessageQueue#Error# => libcrust-analyzer cargo libc 0.2.152 crate/::MSG_ERRQUEUErust-analyzer cargo libc 0.2.152 unix/linux_like/MSG_ERRQUEUE., |
| 119 | }; |
| 120 | |
| 121 | // Safety: |
| 122 | // We have a mutable reference to the control buffer for the duration of the |
| 123 | // call, and controllen is also set to it's length. |
| 124 | // IoSliceMut is ABI compatible with iovec, and we only have 1 which matches |
| 125 | // iovlen msg_name is initialized to point to an owned sockaddr_storage and |
| 126 | // msg_namelen is the size of sockaddr_storage |
| 127 | // If one of the buffers is too small, recvmsg cuts off data at appropriate |
| 128 | // boundary |
| 129 | let received_bytes = loop { |
| 130 | match cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::recvmsgrust-analyzer cargo libc 0.2.152 recvmsg().(self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., &mut mhdr, receive_flags) } as _) { |
| 131 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Interruptedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Interrupted# rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().e.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() => { |
| 132 | // retry when the recv was interrupted |
| 133 | continue; |
| 134 | } |
| 135 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e), |
| 136 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(sent) => break sent as usize, |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | if mhdr.msg_flagsrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_flags. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().libcrust-analyzer cargo libc 0.2.152 crate/::MSG_TRUNCrust-analyzer cargo libc 0.2.152 unix/linux_like/MSG_TRUNC. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 { |
| 141 | tracingrust-analyzer cargo tracing 0.1.37 crate/::inforust-analyzer cargo tracing 0.1.37 macros/info!!( |
| 142 | "truncated packet because it was larger than expected: {} bytes", |
| 143 | packet_buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 144 | ); |
| 145 | } |
| 146 | |
| 147 | if mhdr.msg_flagsrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_flags. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i32][`BitAnd<Self>`]bitand().libcrust-analyzer cargo libc 0.2.152 crate/::MSG_CTRUNCrust-analyzer cargo libc 0.2.152 unix/linux_like/MSG_CTRUNC. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().0 { |
| 148 | tracingrust-analyzer cargo tracing 0.1.37 crate/::inforust-analyzer cargo tracing 0.1.37 macros/info!!("truncated control messages"); |
| 149 | } |
| 150 | |
| 151 | // Clear out the fields for which we are giving up the reference |
| 152 | mhdr.msg_iovrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_iov. = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(); |
| 153 | mhdr.msg_iovlenrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_iovlen. = 0; |
| 154 | mhdr.msg_namerust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_name. = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::null_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/null_mut().(); |
| 155 | mhdr.msg_namelenrust-analyzer cargo libc 0.2.152 unix/linux_like/linux/gnu/msghdr#msg_namelen. = 0; |
| 156 | |
| 157 | // Safety: |
| 158 | // recvmsg ensures that the control buffer contains |
| 159 | // a set of valid control messages and that controllen is |
| 160 | // the length these take up in the buffer. |
| 161 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(( |
| 162 | received_bytes, |
| 163 | unsafe { ControlMessageIteratorrust-analyzer cargo timestamped-socket 0.2.2 control_message/ControlMessageIterator#::newrust-analyzer cargo timestamped-socket 0.2.2 control_message/impl#[`ControlMessageIterator<'a>`]new().(mhdr) }, |
| 164 | addr, |
| 165 | )) |
| 166 | } |
| 167 | |
| 168 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn send_torust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]send_to().(&self, msg: &[u8], addr: sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 169 | // Per posix, it may be invalid to specify a length larger than that of the family. |
| 170 | let len = sockaddr_lenrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/sockaddr_len().(addr); |
| 171 | |
| 172 | // Safety: |
| 173 | // the socket will outlive the call. |
| 174 | // msg points to a block of memory of length msg.len() |
| 175 | // addr points to a block of memory of length at least len |
| 176 | // with flags=0, the other arguments don't matter for safety |
| 177 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { |
| 178 | libcrust-analyzer cargo libc 0.2.152 crate/::sendtorust-analyzer cargo libc 0.2.152 sendto().( |
| 179 | self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., |
| 180 | msg as *const _ as *const c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, |
| 181 | msg.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 182 | 0, |
| 183 | &addr as *const _ as *const sockaddrrust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr#, |
| 184 | len, |
| 185 | ) as _ |
| 186 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 187 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 188 | } |
| 189 | |
| 190 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn sendrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]send().(&self, msg: &[u8]) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 191 | // Safety: |
| 192 | // msg points to a block of memory of length msg.len() |
| 193 | // with flags=0, the other arguments don't matter for safety |
| 194 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::sendrust-analyzer cargo libc 0.2.152 send().(self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., msg as *const _ as *const c_voidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_void#, msg.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), 0) as _ })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 195 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 196 | } |
| 197 | |
| 198 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn getsocknamerust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]getsockname().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#> { |
| 199 | let mut addr = zeroed_sockaddr_storagerust-analyzer cargo timestamped-socket 0.2.2 control_message/zeroed_sockaddr_storage().(); |
| 200 | let mut addr_len: libcrust-analyzer cargo libc 0.2.152 crate/::socklen_trust-analyzer cargo libc 0.2.152 unix/linux_like/linux/socklen_t# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&addr) as _; |
| 201 | // Safety: |
| 202 | // the socket will outlive the call. |
| 203 | // addr points to a block of memory of length addr_len |
| 204 | // addr_len will outlive the call. |
| 205 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { |
| 206 | libcrust-analyzer cargo libc 0.2.152 crate/::getsocknamerust-analyzer cargo libc 0.2.152 getsockname().( |
| 207 | self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., |
| 208 | &mut addr as *mut _ as *mut _, |
| 209 | &mut addr_len as *mut _, |
| 210 | ) |
| 211 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 212 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(addr) |
| 213 | } |
| 214 | |
| 215 | pub(craterust-analyzer cargo timestamped-socket 0.2.2 crate/) fn getpeernamerust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket]getpeername().(&self) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#> { |
| 216 | let mut addr = zeroed_sockaddr_storagerust-analyzer cargo timestamped-socket 0.2.2 control_message/zeroed_sockaddr_storage().(); |
| 217 | let mut addr_len: libcrust-analyzer cargo libc 0.2.152 crate/::socklen_trust-analyzer cargo libc 0.2.152 unix/linux_like/linux/socklen_t# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&addr) as _; |
| 218 | // Safety: |
| 219 | // the socket will outlive the call. |
| 220 | // addr points to a block of memory of length addr_len |
| 221 | // addr_len will outlive the call. |
| 222 | cerrrust-analyzer cargo timestamped-socket 0.2.2 cerr().(unsafe { |
| 223 | libcrust-analyzer cargo libc 0.2.152 crate/::getpeernamerust-analyzer cargo libc 0.2.152 getpeername().( |
| 224 | self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd., |
| 225 | &mut addr as *mut _ as *mut _, |
| 226 | &mut addr_len as *mut _, |
| 227 | ) |
| 228 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 229 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(addr) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | fn sockaddr_lenrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/sockaddr_len().(addr: sockaddr_storagerust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#) -> u32 { |
| 234 | let len: libcrust-analyzer cargo libc 0.2.152 crate/::socklen_trust-analyzer cargo libc 0.2.152 unix/linux_like/linux/socklen_t# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_of_valrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of_val().(&addr) as _; |
| 235 | |
| 236 | len.minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(match addr.ss_familyrust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_storage#ss_family. as _ { |
| 237 | libcrust-analyzer cargo libc 0.2.152 crate/::AF_INETrust-analyzer cargo libc 0.2.152 unix/linux_like/AF_INET. => stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_inrust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_in#>() as _, |
| 238 | libcrust-analyzer cargo libc 0.2.152 crate/::AF_INET6rust-analyzer cargo libc 0.2.152 unix/linux_like/AF_INET6. => stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::size_ofrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/size_of().::<libcrust-analyzer cargo libc 0.2.152 crate/::sockaddr_in6rust-analyzer cargo libc 0.2.152 unix/linux_like/sockaddr_in6#>() as _, |
| 239 | _ => len, |
| 240 | }) |
| 241 | } |
| 242 | |
| 243 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for RawSocketrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket# { |
| 244 | fn droprust-analyzer cargo timestamped-socket 0.2.2 raw_socket/impl#[RawSocket][Drop]drop().(&mut self) { |
| 245 | // Safety: close is always safe to call on a file descriptor |
| 246 | unsafe { libcrust-analyzer cargo libc 0.2.152 crate/::closerust-analyzer cargo libc 0.2.152 close().(self.fdrust-analyzer cargo timestamped-socket 0.2.2 raw_socket/RawSocket#fd.) }; |
| 247 | } |
| 248 | } |