Sha256: 2d9c704b059fdd0be6b844be4db8ef4dcad902fc146e9cf55eae5a5eef2fdb86

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

use std::io;
use std::mem;
use std::net::{self, SocketAddr};
#[cfg(not(target_os = "hermit"))]
use std::os::fd::{AsRawFd, FromRawFd};
// TODO: once <https://github.com/rust-lang/rust/issues/126198> is fixed this
// can use `std::os::fd` and be merged with the above.
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, FromRawFd};

use crate::sys::unix::net::{new_ip_socket, socket_addr};

pub fn bind(addr: SocketAddr) -> io::Result<net::UdpSocket> {
    let fd = new_ip_socket(addr, libc::SOCK_DGRAM)?;
    let socket = unsafe { net::UdpSocket::from_raw_fd(fd) };

    let (raw_addr, raw_addr_length) = socket_addr(&addr);
    syscall!(bind(fd, raw_addr.as_ptr(), raw_addr_length))?;

    Ok(socket)
}

pub(crate) fn only_v6(socket: &net::UdpSocket) -> io::Result<bool> {
    let mut optval: libc::c_int = 0;
    let mut optlen = mem::size_of::<libc::c_int>() as libc::socklen_t;

    syscall!(getsockopt(
        socket.as_raw_fd(),
        libc::IPPROTO_IPV6,
        libc::IPV6_V6ONLY,
        &mut optval as *mut _ as *mut _,
        &mut optlen,
    ))?;

    Ok(optval != 0)
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/mio-1.0.3/src/sys/unix/udp.rs
wasmtime-28.0.0 ./ext/cargo-vendor/mio-1.0.3/src/sys/unix/udp.rs
wasmtime-27.0.0 ./ext/cargo-vendor/mio-1.0.2/src/sys/unix/udp.rs
wasmtime-26.0.0 ./ext/cargo-vendor/mio-1.0.2/src/sys/unix/udp.rs
wasmtime-25.0.2 ./ext/cargo-vendor/mio-1.0.2/src/sys/unix/udp.rs
wasmtime-25.0.1 ./ext/cargo-vendor/mio-1.0.2/src/sys/unix/udp.rs
wasmtime-25.0.0 ./ext/cargo-vendor/mio-1.0.2/src/sys/unix/udp.rs
wasmtime-24.0.0 ./ext/cargo-vendor/mio-1.0.2/src/sys/unix/udp.rs