summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/net
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/rustix/src/net
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/net')
-rw-r--r--vendor/rustix/src/net/send_recv/msg.rs12
-rw-r--r--vendor/rustix/src/net/socket.rs9
-rw-r--r--vendor/rustix/src/net/sockopt.rs398
-rw-r--r--vendor/rustix/src/net/types.rs567
4 files changed, 679 insertions, 307 deletions
diff --git a/vendor/rustix/src/net/send_recv/msg.rs b/vendor/rustix/src/net/send_recv/msg.rs
index 5fefb2e24..431aefa03 100644
--- a/vendor/rustix/src/net/send_recv/msg.rs
+++ b/vendor/rustix/src/net/send_recv/msg.rs
@@ -107,8 +107,8 @@ impl<'buf, 'slice, 'fd> SendAncillaryBuffer<'buf, 'slice, 'fd> {
/// Returns a pointer to the message data.
pub(crate) fn as_control_ptr(&mut self) -> *mut u8 {
- // When the length is zero, we may be using a `&[]` address, which
- // may be an invalid but non-null pointer, and on some platforms, that
+ // When the length is zero, we may be using a `&[]` address, which may
+ // be an invalid but non-null pointer, and on some platforms, that
// causes `sendmsg` to fail with `EFAULT` or `EINVAL`
#[cfg(not(linux_kernel))]
if self.length == 0 {
@@ -227,8 +227,8 @@ impl<'buf> RecvAncillaryBuffer<'buf> {
/// Returns a pointer to the message data.
pub(crate) fn as_control_ptr(&mut self) -> *mut u8 {
- // When the length is zero, we may be using a `&[]` address, which
- // may be an invalid but non-null pointer, and on some platforms, that
+ // When the length is zero, we may be using a `&[]` address, which may
+ // be an invalid but non-null pointer, and on some platforms, that
// causes `sendmsg` to fail with `EFAULT` or `EINVAL`
#[cfg(not(linux_kernel))]
if self.buffer.is_empty() {
@@ -686,9 +686,9 @@ impl<T> DoubleEndedIterator for AncillaryIter<'_, T> {
mod messages {
use crate::backend::c;
+ use crate::backend::net::msghdr;
use core::iter::FusedIterator;
use core::marker::PhantomData;
- use core::mem::zeroed;
use core::ptr::NonNull;
/// An iterator over the messages in an ancillary buffer.
@@ -709,7 +709,7 @@ mod messages {
/// Create a new iterator over messages from a byte buffer.
pub(super) fn new(buf: &'buf mut [u8]) -> Self {
let msghdr = {
- let mut h: c::msghdr = unsafe { zeroed() };
+ let mut h = msghdr::zero_msghdr();
h.msg_control = buf.as_mut_ptr().cast();
h.msg_controllen = buf.len().try_into().expect("buffer too large for msghdr");
h
diff --git a/vendor/rustix/src/net/socket.rs b/vendor/rustix/src/net/socket.rs
index 23cc00aed..8727ca53b 100644
--- a/vendor/rustix/src/net/socket.rs
+++ b/vendor/rustix/src/net/socket.rs
@@ -13,7 +13,8 @@ pub use backend::net::addr::SocketAddrUnix;
/// however it is not safe in general to rely on this, as file descriptors may
/// be unexpectedly allocated on other threads or in libraries.
///
-/// To pass extra flags such as [`SocketFlags::CLOEXEC`], use [`socket_with`].
+/// To pass extra flags such as [`SocketFlags::CLOEXEC`] or
+/// [`SocketFlags::NONBLOCK`], use [`socket_with`].
///
/// # References
/// - [Beej's Guide to Network Programming]
@@ -82,6 +83,7 @@ pub fn socket(
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=socket&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/socket
/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Creating-a-Socket.html
+#[doc(alias("socket"))]
#[inline]
pub fn socket_with(
domain: AddressFamily,
@@ -271,6 +273,10 @@ pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()>
/// `connect(sockfd, addr)`—Initiates a connection to an IP address.
///
+/// On Windows, a non-blocking socket returns [`Errno::WOULDBLOCK`] if the
+/// connection cannot be completed immediately, rather than
+/// `Errno::INPROGRESS`.
+///
/// # References
/// - [Beej's Guide to Network Programming]
/// - [POSIX]
@@ -295,6 +301,7 @@ pub fn bind_unix<Fd: AsFd>(sockfd: Fd, addr: &SocketAddrUnix) -> io::Result<()>
/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=connect&section=2
/// [illumos]: https://illumos.org/man/3SOCKET/connect
/// [glibc]: https://www.gnu.org/software/libc/manual/html_node/Connecting.html
+/// [`Errno::WOULDBLOCK`]: io::Errno::WOULDBLOCK
pub fn connect<Fd: AsFd>(sockfd: Fd, addr: &SocketAddr) -> io::Result<()> {
_connect(sockfd.as_fd(), addr)
}
diff --git a/vendor/rustix/src/net/sockopt.rs b/vendor/rustix/src/net/sockopt.rs
index b21d4a35c..1939155d9 100644
--- a/vendor/rustix/src/net/sockopt.rs
+++ b/vendor/rustix/src/net/sockopt.rs
@@ -6,6 +6,18 @@
#![doc(alias = "getsockopt")]
#![doc(alias = "setsockopt")]
+#[cfg(not(any(
+ apple,
+ windows,
+ target_os = "aix",
+ target_os = "dragonfly",
+ target_os = "emscripten",
+ target_os = "espidf",
+ target_os = "haiku",
+ target_os = "netbsd",
+ target_os = "nto",
+)))]
+use crate::net::AddressFamily;
use crate::net::{Ipv4Addr, Ipv6Addr, SocketType};
use crate::{backend, io};
use backend::c;
@@ -103,6 +115,44 @@ pub fn set_socket_reuseaddr<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
backend::net::syscalls::sockopt::set_socket_reuseaddr(fd.as_fd(), value)
}
+/// `getsockopt(fd, SOL_SOCKET, SO_REUSEADDR)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `sys/socket.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `socket`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `SOL_SOCKET` options]
+/// - [Apple]
+/// - [FreeBSD]
+/// - [NetBSD]
+/// - [OpenBSD]
+/// - [DragonFly BSD]
+/// - [illumos]
+/// - [glibc `getsockopt`]
+/// - [glibc `SOL_SOCKET` Options]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
+/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [NetBSD]: https://man.netbsd.org/getsockopt.2
+/// [OpenBSD]: https://man.openbsd.org/getsockopt.2
+/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt
+/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html
+/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html
+#[inline]
+#[doc(alias = "SO_REUSEADDR")]
+pub fn get_socket_reuseaddr<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
+ backend::net::syscalls::sockopt::get_socket_reuseaddr(fd.as_fd())
+}
+
/// `setsockopt(fd, SOL_SOCKET, SO_BROADCAST, broadcast)`
///
/// # References
@@ -712,6 +762,92 @@ pub fn get_socket_send_buffer_size<Fd: AsFd>(fd: Fd) -> io::Result<usize> {
backend::net::syscalls::sockopt::get_socket_send_buffer_size(fd.as_fd())
}
+/// `getsockopt(fd, SOL_SOCKET, SO_DOMAIN)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `sys/socket.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `socket`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `SOL_SOCKET` options]
+/// - [Apple]
+/// - [FreeBSD]
+/// - [NetBSD]
+/// - [OpenBSD]
+/// - [DragonFly BSD]
+/// - [illumos]
+/// - [glibc `getsockopt`]
+/// - [glibc `SOL_SOCKET` Options]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
+/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [NetBSD]: https://man.netbsd.org/getsockopt.2
+/// [OpenBSD]: https://man.openbsd.org/getsockopt.2
+/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt
+/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html
+/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html
+#[cfg(not(any(
+ apple,
+ windows,
+ target_os = "aix",
+ target_os = "dragonfly",
+ target_os = "emscripten",
+ target_os = "espidf",
+ target_os = "haiku",
+ target_os = "netbsd",
+ target_os = "nto",
+)))]
+#[inline]
+#[doc(alias = "SO_DOMAIN")]
+pub fn get_socket_domain<Fd: AsFd>(fd: Fd) -> io::Result<AddressFamily> {
+ backend::net::syscalls::sockopt::get_socket_domain(fd.as_fd())
+}
+
+/// `getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `sys/socket.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `socket`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `SOL_SOCKET` options]
+/// - [FreeBSD]
+/// - [NetBSD]
+/// - [OpenBSD]
+/// - [DragonFly BSD]
+/// - [illumos]
+/// - [glibc `getsockopt`]
+/// - [glibc `SOL_SOCKET` Options]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `sys/socket.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `socket`]: https://man7.org/linux/man-pages/man7/socket.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `SOL_SOCKET` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options
+/// [FreeBSD]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [NetBSD]: https://man.netbsd.org/getsockopt.2
+/// [OpenBSD]: https://man.openbsd.org/getsockopt.2
+/// [DragonFly BSD]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [illumos]: https://illumos.org/man/3SOCKET/getsockopt
+/// [glibc `getsockopt`]: https://www.gnu.org/software/libc/manual/html_node/Socket-Option-Functions.html
+/// [glibc `SOL_SOCKET` options]: https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html
+#[cfg(not(apple))] // Apple platforms declare the constant, but do not actually implement it.
+#[inline]
+#[doc(alias = "SO_ACCEPTCONN")]
+pub fn get_socket_acceptconn<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
+ backend::net::syscalls::sockopt::get_socket_acceptconn(fd.as_fd())
+}
+
/// `setsockopt(fd, IPPROTO_IP, IP_TTL, ttl)`
///
/// # References
@@ -1629,6 +1765,268 @@ pub fn get_tcp_nodelay<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
backend::net::syscalls::sockopt::get_tcp_nodelay(fd.as_fd())
}
+/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, count)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `netinet/tcp.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `tcp`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `IPPROTO_TCP` options]
+/// - [Apple `getsockopt`]
+/// - [Apple `tcp`]
+/// - [FreeBSD `getsockopt`]
+/// - [FreeBSD `tcp`]
+/// - [NetBSD `getsockopt`]
+/// - [NetBSD `tcp`]
+/// - [DragonFly BSD `getsockopt`]
+/// - [DragonFly BSD `tcp`]
+/// - [illumos `getsockopt`]
+/// - [illumos `tcp`]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
+/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html
+/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4
+/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2
+/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4
+/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp&section=4
+/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt
+/// [illumos `tcp`]: https://illumos.org/man/4P/tcp
+#[inline]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
+#[doc(alias = "TCP_KEEPCNT")]
+pub fn set_tcp_keepcnt<Fd: AsFd>(fd: Fd, count: u32) -> io::Result<()> {
+ backend::net::syscalls::sockopt::set_tcp_keepcnt(fd.as_fd(), count)
+}
+
+/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `netinet/tcp.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `tcp`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `IPPROTO_TCP` options]
+/// - [Apple `getsockopt`]
+/// - [Apple `tcp`]
+/// - [FreeBSD `getsockopt`]
+/// - [FreeBSD `tcp`]
+/// - [NetBSD `getsockopt`]
+/// - [NetBSD `tcp`]
+/// - [DragonFly BSD `getsockopt`]
+/// - [DragonFly BSD `tcp`]
+/// - [illumos `getsockopt`]
+/// - [illumos `tcp`]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
+/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html
+/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4
+/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2
+/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4
+/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp&section=4
+/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt
+/// [illumos `tcp`]: https://illumos.org/man/4P/tcp
+#[inline]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
+#[doc(alias = "TCP_KEEPCNT")]
+pub fn get_tcp_keepcnt<Fd: AsFd>(fd: Fd) -> io::Result<u32> {
+ backend::net::syscalls::sockopt::get_tcp_keepcnt(fd.as_fd())
+}
+
+/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, duration)`
+///
+/// `TCP_KEEPALIVE` on Apple platforms.
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `netinet/tcp.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `tcp`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `IPPROTO_TCP` options]
+/// - [Apple `getsockopt`]
+/// - [Apple `tcp`]
+/// - [FreeBSD `getsockopt`]
+/// - [FreeBSD `tcp`]
+/// - [NetBSD `getsockopt`]
+/// - [NetBSD `tcp`]
+/// - [DragonFly BSD `getsockopt`]
+/// - [DragonFly BSD `tcp`]
+/// - [illumos `getsockopt`]
+/// - [illumos `tcp`]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
+/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html
+/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4
+/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2
+/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4
+/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp&section=4
+/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt
+/// [illumos `tcp`]: https://illumos.org/man/4P/tcp
+#[inline]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
+#[doc(alias = "TCP_KEEPIDLE")]
+pub fn set_tcp_keepidle<Fd: AsFd>(fd: Fd, duration: Duration) -> io::Result<()> {
+ backend::net::syscalls::sockopt::set_tcp_keepidle(fd.as_fd(), duration)
+}
+
+/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE)`
+///
+/// `TCP_KEEPALIVE` on Apple platforms.
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `netinet/tcp.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `tcp`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `IPPROTO_TCP` options]
+/// - [Apple `getsockopt`]
+/// - [Apple `tcp`]
+/// - [FreeBSD `getsockopt`]
+/// - [FreeBSD `tcp`]
+/// - [NetBSD `getsockopt`]
+/// - [NetBSD `tcp`]
+/// - [DragonFly BSD `getsockopt`]
+/// - [DragonFly BSD `tcp`]
+/// - [illumos `getsockopt`]
+/// - [illumos `tcp`]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
+/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html
+/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4
+/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2
+/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4
+/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp&section=4
+/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt
+/// [illumos `tcp`]: https://illumos.org/man/4P/tcp
+#[inline]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
+#[doc(alias = "TCP_KEEPIDLE")]
+pub fn get_tcp_keepidle<Fd: AsFd>(fd: Fd) -> io::Result<Duration> {
+ backend::net::syscalls::sockopt::get_tcp_keepidle(fd.as_fd())
+}
+
+/// `setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, duration)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `netinet/tcp.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `tcp`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `IPPROTO_TCP` options]
+/// - [Apple `getsockopt`]
+/// - [Apple `tcp`]
+/// - [FreeBSD `getsockopt`]
+/// - [FreeBSD `tcp`]
+/// - [NetBSD `getsockopt`]
+/// - [NetBSD `tcp`]
+/// - [DragonFly BSD `getsockopt`]
+/// - [DragonFly BSD `tcp`]
+/// - [illumos `getsockopt`]
+/// - [illumos `tcp`]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
+/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html
+/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4
+/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2
+/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4
+/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp&section=4
+/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt
+/// [illumos `tcp`]: https://illumos.org/man/4P/tcp
+#[inline]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
+#[doc(alias = "TCP_KEEPINTVL")]
+pub fn set_tcp_keepintvl<Fd: AsFd>(fd: Fd, duration: Duration) -> io::Result<()> {
+ backend::net::syscalls::sockopt::set_tcp_keepintvl(fd.as_fd(), duration)
+}
+
+/// `getsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL)`
+///
+/// # References
+/// - [POSIX `getsockopt`]
+/// - [POSIX `netinet/tcp.h`]
+/// - [Linux `getsockopt`]
+/// - [Linux `tcp`]
+/// - [Winsock2 `getsockopt`]
+/// - [Winsock2 `IPPROTO_TCP` options]
+/// - [Apple `getsockopt`]
+/// - [Apple `tcp`]
+/// - [FreeBSD `getsockopt`]
+/// - [FreeBSD `tcp`]
+/// - [NetBSD `getsockopt`]
+/// - [NetBSD `tcp`]
+/// - [DragonFly BSD `getsockopt`]
+/// - [DragonFly BSD `tcp`]
+/// - [illumos `getsockopt`]
+/// - [illumos `tcp`]
+///
+/// [POSIX `getsockopt`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html
+/// [POSIX `netinet/tcp.h`]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
+/// [Linux `getsockopt`]: https://man7.org/linux/man-pages/man2/getsockopt.2.html
+/// [Linux `tcp`]: https://man7.org/linux/man-pages/man7/tcp.7.html
+/// [Winsock2 `getsockopt`]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt
+/// [Winsock2 `IPPROTO_TCP` options]: https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options
+/// [Apple `getsockopt`]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getsockopt.2.html
+/// [Apple `tcp`]: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man4/tcp.4.auto.html
+/// [FreeBSD `getsockopt`]: https://man.freebsd.org/cgi/man.cgi?query=getsockopt&sektion=2
+/// [FreeBSD `tcp`]: https://man.freebsd.org/cgi/man.cgi?query=tcp&sektion=4
+/// [NetBSD `getsockopt`]: https://man.netbsd.org/getsockopt.2
+/// [NetBSD `tcp`]: https://man.netbsd.org/tcp.4
+/// [DragonFly BSD `getsockopt`]: https://man.dragonflybsd.org/?command=getsockopt&section=2
+/// [DragonFly BSD `tcp`]: https://man.dragonflybsd.org/?command=tcp&section=4
+/// [illumos `getsockopt`]: https://illumos.org/man/3SOCKET/getsockopt
+/// [illumos `tcp`]: https://illumos.org/man/4P/tcp
+#[inline]
+#[cfg(not(any(target_os = "openbsd", target_os = "haiku", target_os = "nto")))]
+#[doc(alias = "TCP_KEEPINTVL")]
+pub fn get_tcp_keepintvl<Fd: AsFd>(fd: Fd) -> io::Result<Duration> {
+ backend::net::syscalls::sockopt::get_tcp_keepintvl(fd.as_fd())
+}
+
#[test]
fn test_sizes() {
use c::c_int;
diff --git a/vendor/rustix/src/net/types.rs b/vendor/rustix/src/net/types.rs
index a2c019b42..53116f9c8 100644
--- a/vendor/rustix/src/net/types.rs
+++ b/vendor/rustix/src/net/types.rs
@@ -1,10 +1,9 @@
-#![allow(unsafe_code)]
+//! Types and constants for `rustix::net`.
use crate::backend::c;
use bitflags::bitflags;
/// A type for holding raw integer socket types.
-#[doc(hidden)]
pub type RawSocketType = u32;
/// `SOCK_*` constants for use with [`socket`].
@@ -48,10 +47,14 @@ impl SocketType {
}
/// A type for holding raw integer address families.
-#[doc(hidden)]
pub type RawAddressFamily = c::sa_family_t;
-/// `AF_*` constants.
+/// `AF_*` constants for use with [`socket`], [`socket_with`], and
+/// [`socketpair`].
+///
+/// [`socket`]: crate::net::socket()
+/// [`socket_with`]: crate::net::socket_with
+/// [`socketpair`]: crate::net::socketpair()
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct AddressFamily(pub(crate) RawAddressFamily);
@@ -85,6 +88,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -98,13 +102,17 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
)))]
pub const AX25: Self = Self(c::AF_AX25 as _);
/// `AF_IPX`
- #[cfg(not(target_os = "espidf"))]
+ #[cfg(not(any(
+ target_os = "espidf",
+ target_os = "aix",
+ )))]
pub const IPX: Self = Self(c::AF_IPX as _);
/// `AF_APPLETALK`
#[cfg(not(target_os = "espidf"))]
@@ -114,6 +122,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -124,6 +133,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -134,6 +144,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -143,6 +154,7 @@ impl AddressFamily {
#[cfg(not(any(
bsd,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -153,6 +165,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -166,6 +179,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -176,6 +190,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -185,6 +200,7 @@ impl AddressFamily {
#[cfg(not(any(
bsd,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -199,6 +215,7 @@ impl AddressFamily {
#[cfg(not(any(
bsd,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -209,6 +226,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -219,6 +237,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -229,6 +248,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -239,6 +259,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -251,6 +272,7 @@ impl AddressFamily {
#[cfg(not(any(
bsd,
solarish,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -261,6 +283,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -271,6 +294,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -281,6 +305,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -291,6 +316,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -301,19 +327,27 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
)))]
pub const TIPC: Self = Self(c::AF_TIPC as _);
/// `AF_BLUETOOTH`
- #[cfg(not(any(apple, solarish, windows, target_os = "espidf")))]
+ #[cfg(not(any(
+ apple,
+ solarish,
+ windows,
+ target_os = "aix",
+ target_os = "espidf",
+ )))]
pub const BLUETOOTH: Self = Self(c::AF_BLUETOOTH as _);
/// `AF_IUCV`
#[cfg(not(any(
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -324,19 +358,27 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
)))]
pub const RXRPC: Self = Self(c::AF_RXRPC as _);
/// `AF_ISDN`
- #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))]
+ #[cfg(not(any(
+ solarish,
+ windows,
+ target_os = "aix",
+ target_os = "espidf",
+ target_os = "haiku",
+ )))]
pub const ISDN: Self = Self(c::AF_ISDN as _);
/// `AF_PHONET`
#[cfg(not(any(
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -347,6 +389,7 @@ impl AddressFamily {
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
@@ -410,7 +453,7 @@ impl AddressFamily {
#[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
pub const IMPLINK: Self = Self(c::AF_IMPLINK as _);
/// `AF_IEEE80211`
- #[cfg(any(apple, freebsdlike, linuxlike, target_os = "netbsd"))]
+ #[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
pub const IEEE80211: Self = Self(c::AF_IEEE80211 as _);
/// `AF_INET6_SDP`
#[cfg(target_os = "freebsd")]
@@ -437,7 +480,7 @@ impl AddressFamily {
#[cfg(any(netbsdlike, target_os = "dragonfly", target_os = "emscripten", target_os = "fuchsia"))]
pub const MPLS: Self = Self(c::AF_MPLS as _);
/// `AF_NATM`
- #[cfg(any(bsd, target_os = "aix", target_os = "nto"))]
+ #[cfg(any(bsd, target_os = "nto"))]
pub const NATM: Self = Self(c::AF_NATM as _);
/// `AF_NBS`
#[cfg(solarish)]
@@ -497,7 +540,7 @@ impl AddressFamily {
#[cfg(target_os = "freebsd")]
pub const SCLUSTER: Self = Self(c::AF_SCLUSTER as _);
/// `AF_SIP`
- #[cfg(any(apple, target_os = "freebsd", target_os = "opensbd"))]
+ #[cfg(any(apple, target_os = "freebsd", target_os = "openbsd"))]
pub const SIP: Self = Self(c::AF_SIP as _);
/// `AF_SLOW`
#[cfg(target_os = "freebsd")]
@@ -532,9 +575,15 @@ impl AddressFamily {
}
/// A type for holding raw integer protocols.
-#[doc(hidden)]
pub type RawProtocol = core::num::NonZeroU32;
+const fn new_raw_protocol(u: u32) -> RawProtocol {
+ match RawProtocol::new(u) {
+ Some(p) => p,
+ None => panic!("new_raw_protocol: protocol must be non-zero"),
+ }
+}
+
/// `IPPROTO_*` and other constants for use with [`socket`], [`socket_with`],
/// and [`socketpair`] when a nondefault value is desired. See the [`ipproto`],
/// [`sysproto`], and [`netlink`] modules for possible values.
@@ -555,104 +604,105 @@ pub struct Protocol(pub(crate) RawProtocol);
///
/// For `IPPROTO_IP`, pass `None` as the `protocol` argument.
pub mod ipproto {
- use super::{Protocol, RawProtocol};
+ use super::{new_raw_protocol, Protocol};
use crate::backend::c;
/// `IPPROTO_ICMP`
- pub const ICMP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ICMP as _) });
+ pub const ICMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ICMP as _));
/// `IPPROTO_IGMP`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const IGMP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IGMP as _) });
+ pub const IGMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IGMP as _));
/// `IPPROTO_IPIP`
#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))]
- pub const IPIP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IPIP as _) });
+ pub const IPIP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IPIP as _));
/// `IPPROTO_TCP`
- pub const TCP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_TCP as _) });
+ pub const TCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_TCP as _));
/// `IPPROTO_EGP`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const EGP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_EGP as _) });
+ pub const EGP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_EGP as _));
/// `IPPROTO_PUP`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const PUP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_PUP as _) });
+ pub const PUP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_PUP as _));
/// `IPPROTO_UDP`
- pub const UDP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_UDP as _) });
+ pub const UDP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_UDP as _));
/// `IPPROTO_IDP`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const IDP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IDP as _) });
+ pub const IDP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IDP as _));
/// `IPPROTO_TP`
#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))]
- pub const TP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_TP as _) });
+ pub const TP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_TP as _));
/// `IPPROTO_DCCP`
#[cfg(not(any(
apple,
solarish,
windows,
+ target_os = "aix",
target_os = "dragonfly",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
target_os = "openbsd",
)))]
- pub const DCCP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_DCCP as _) });
+ pub const DCCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_DCCP as _));
/// `IPPROTO_IPV6`
- pub const IPV6: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_IPV6 as _) });
+ pub const IPV6: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IPV6 as _));
/// `IPPROTO_RSVP`
#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))]
- pub const RSVP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_RSVP as _) });
+ pub const RSVP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_RSVP as _));
/// `IPPROTO_GRE`
#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))]
- pub const GRE: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_GRE as _) });
+ pub const GRE: Protocol = Protocol(new_raw_protocol(c::IPPROTO_GRE as _));
/// `IPPROTO_ESP`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const ESP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ESP as _) });
+ pub const ESP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ESP as _));
/// `IPPROTO_AH`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const AH: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_AH as _) });
+ pub const AH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_AH as _));
/// `IPPROTO_MTP`
#[cfg(not(any(
solarish,
netbsdlike,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
)))]
- pub const MTP: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MTP as _) });
+ pub const MTP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MTP as _));
/// `IPPROTO_BEETPH`
#[cfg(not(any(
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto"
)))]
- pub const BEETPH: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_BEETPH as _) });
+ pub const BEETPH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_BEETPH as _));
/// `IPPROTO_ENCAP`
- #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))]
- pub const ENCAP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ENCAP as _) });
+ #[cfg(not(any(
+ solarish,
+ windows,
+ target_os = "aix",
+ target_os = "espidf",
+ target_os = "haiku",
+ )))]
+ pub const ENCAP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ENCAP as _));
/// `IPPROTO_PIM`
- #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const PIM: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_PIM as _) });
+ #[cfg(not(any(solarish, target_os = "aix", target_os = "espidf", target_os = "haiku")))]
+ pub const PIM: Protocol = Protocol(new_raw_protocol(c::IPPROTO_PIM as _));
/// `IPPROTO_COMP`
#[cfg(not(any(
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "espidf",
target_os = "haiku",
target_os = "nto"
)))]
- pub const COMP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_COMP as _) });
+ pub const COMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_COMP as _));
/// `IPPROTO_SCTP`
#[cfg(not(any(
solarish,
@@ -661,61 +711,57 @@ pub mod ipproto {
target_os = "haiku",
target_os = "openbsd"
)))]
- pub const SCTP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_SCTP as _) });
+ pub const SCTP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_SCTP as _));
/// `IPPROTO_UDPLITE`
#[cfg(not(any(
apple,
netbsdlike,
solarish,
windows,
+ target_os = "aix",
target_os = "dragonfly",
target_os = "espidf",
target_os = "haiku",
target_os = "nto",
)))]
- pub const UDPLITE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_UDPLITE as _) });
+ pub const UDPLITE: Protocol = Protocol(new_raw_protocol(c::IPPROTO_UDPLITE as _));
/// `IPPROTO_MPLS`
#[cfg(not(any(
apple,
solarish,
windows,
+ target_os = "aix",
target_os = "dragonfly",
target_os = "espidf",
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
)))]
- pub const MPLS: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MPLS as _) });
+ pub const MPLS: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MPLS as _));
/// `IPPROTO_ETHERNET`
#[cfg(linux_kernel)]
- pub const ETHERNET: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ETHERNET as _) });
+ pub const ETHERNET: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ETHERNET as _));
/// `IPPROTO_RAW`
#[cfg(not(target_os = "espidf"))]
- pub const RAW: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_RAW as _) });
+ pub const RAW: Protocol = Protocol(new_raw_protocol(c::IPPROTO_RAW as _));
/// `IPPROTO_MPTCP`
#[cfg(not(any(
bsd,
solarish,
windows,
+ target_os = "aix",
target_os = "emscripten",
target_os = "espidf",
target_os = "fuchsia",
target_os = "haiku",
target_os = "nto",
)))]
- pub const MPTCP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MPTCP as _) });
+ pub const MPTCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MPTCP as _));
/// `IPPROTO_FRAGMENT`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const FRAGMENT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_FRAGMENT as _) });
+ pub const FRAGMENT: Protocol = Protocol(new_raw_protocol(c::IPPROTO_FRAGMENT as _));
/// `IPPROTO_ICMPV6`
- pub const ICMPV6: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ICMPV6 as _) });
+ pub const ICMPV6: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ICMPV6 as _));
/// `IPPROTO_MH`
#[cfg(not(any(
apple,
@@ -727,30 +773,27 @@ pub mod ipproto {
target_os = "haiku",
target_os = "nto",
)))]
- pub const MH: Protocol = Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_MH as _) });
+ pub const MH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MH as _));
/// `IPPROTO_ROUTING`
#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))]
- pub const ROUTING: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::IPPROTO_ROUTING as _) });
+ pub const ROUTING: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ROUTING as _));
}
/// `SYSPROTO_*` constants.
pub mod sysproto {
#[cfg(apple)]
use {
- super::{Protocol, RawProtocol},
+ super::{new_raw_protocol, Protocol},
crate::backend::c,
};
/// `SYSPROTO_EVENT`
#[cfg(apple)]
- pub const EVENT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::SYSPROTO_EVENT as _) });
+ pub const EVENT: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_EVENT as _));
/// `SYSPROTO_CONTROL`
#[cfg(apple)]
- pub const CONTROL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::SYSPROTO_CONTROL as _) });
+ pub const CONTROL: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_CONTROL as _));
}
/// `NETLINK_*` constants.
@@ -759,566 +802,478 @@ pub mod sysproto {
pub mod netlink {
#[cfg(linux_kernel)]
use {
- super::{Protocol, RawProtocol},
+ super::{new_raw_protocol, Protocol},
crate::backend::c,
};
/// `NETLINK_UNUSED`
#[cfg(linux_kernel)]
- pub const UNUSED: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_UNUSED as _) });
+ pub const UNUSED: Protocol = Protocol(new_raw_protocol(c::NETLINK_UNUSED as _));
/// `NETLINK_USERSOCK`
#[cfg(linux_kernel)]
- pub const USERSOCK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_USERSOCK as _) });
+ pub const USERSOCK: Protocol = Protocol(new_raw_protocol(c::NETLINK_USERSOCK as _));
/// `NETLINK_FIREWALL`
#[cfg(linux_kernel)]
- pub const FIREWALL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_FIREWALL as _) });
+ pub const FIREWALL: Protocol = Protocol(new_raw_protocol(c::NETLINK_FIREWALL as _));
/// `NETLINK_SOCK_DIAG`
#[cfg(linux_kernel)]
- pub const SOCK_DIAG: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_SOCK_DIAG as _) });
+ pub const SOCK_DIAG: Protocol = Protocol(new_raw_protocol(c::NETLINK_SOCK_DIAG as _));
/// `NETLINK_NFLOG`
#[cfg(linux_kernel)]
- pub const NFLOG: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_NFLOG as _) });
+ pub const NFLOG: Protocol = Protocol(new_raw_protocol(c::NETLINK_NFLOG as _));
/// `NETLINK_XFRM`
#[cfg(linux_kernel)]
- pub const XFRM: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_XFRM as _) });
+ pub const XFRM: Protocol = Protocol(new_raw_protocol(c::NETLINK_XFRM as _));
/// `NETLINK_SELINUX`
#[cfg(linux_kernel)]
- pub const SELINUX: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_SELINUX as _) });
+ pub const SELINUX: Protocol = Protocol(new_raw_protocol(c::NETLINK_SELINUX as _));
/// `NETLINK_ISCSI`
#[cfg(linux_kernel)]
- pub const ISCSI: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_ISCSI as _) });
+ pub const ISCSI: Protocol = Protocol(new_raw_protocol(c::NETLINK_ISCSI as _));
/// `NETLINK_AUDIT`
#[cfg(linux_kernel)]
- pub const AUDIT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_AUDIT as _) });
+ pub const AUDIT: Protocol = Protocol(new_raw_protocol(c::NETLINK_AUDIT as _));
/// `NETLINK_FIB_LOOKUP`
#[cfg(linux_kernel)]
- pub const FIB_LOOKUP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_FIB_LOOKUP as _) });
+ pub const FIB_LOOKUP: Protocol = Protocol(new_raw_protocol(c::NETLINK_FIB_LOOKUP as _));
/// `NETLINK_CONNECTOR`
#[cfg(linux_kernel)]
- pub const CONNECTOR: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_CONNECTOR as _) });
+ pub const CONNECTOR: Protocol = Protocol(new_raw_protocol(c::NETLINK_CONNECTOR as _));
/// `NETLINK_NETFILTER`
#[cfg(linux_kernel)]
- pub const NETFILTER: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_NETFILTER as _) });
+ pub const NETFILTER: Protocol = Protocol(new_raw_protocol(c::NETLINK_NETFILTER as _));
/// `NETLINK_IP6_FW`
#[cfg(linux_kernel)]
- pub const IP6_FW: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_IP6_FW as _) });
+ pub const IP6_FW: Protocol = Protocol(new_raw_protocol(c::NETLINK_IP6_FW as _));
/// `NETLINK_DNRTMSG`
#[cfg(linux_kernel)]
- pub const DNRTMSG: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_DNRTMSG as _) });
+ pub const DNRTMSG: Protocol = Protocol(new_raw_protocol(c::NETLINK_DNRTMSG as _));
/// `NETLINK_KOBJECT_UEVENT`
#[cfg(linux_kernel)]
- pub const KOBJECT_UEVENT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_KOBJECT_UEVENT as _) });
+ pub const KOBJECT_UEVENT: Protocol = Protocol(new_raw_protocol(c::NETLINK_KOBJECT_UEVENT as _));
/// `NETLINK_GENERIC`
// This is defined on FreeBSD too, but it has the value 0, so it doesn't
// fit in or `NonZeroU32`. It's unclear whether FreeBSD intends
// `NETLINK_GENERIC` to be the default when Linux has `NETLINK_ROUTE`
// as the default.
#[cfg(linux_kernel)]
- pub const GENERIC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_GENERIC as _) });
+ pub const GENERIC: Protocol = Protocol(new_raw_protocol(c::NETLINK_GENERIC as _));
/// `NETLINK_SCSITRANSPORT`
#[cfg(linux_kernel)]
- pub const SCSITRANSPORT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_SCSITRANSPORT as _) });
+ pub const SCSITRANSPORT: Protocol = Protocol(new_raw_protocol(c::NETLINK_SCSITRANSPORT as _));
/// `NETLINK_ECRYPTFS`
#[cfg(linux_kernel)]
- pub const ECRYPTFS: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_ECRYPTFS as _) });
+ pub const ECRYPTFS: Protocol = Protocol(new_raw_protocol(c::NETLINK_ECRYPTFS as _));
/// `NETLINK_RDMA`
#[cfg(linux_kernel)]
- pub const RDMA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_RDMA as _) });
+ pub const RDMA: Protocol = Protocol(new_raw_protocol(c::NETLINK_RDMA as _));
/// `NETLINK_CRYPTO`
#[cfg(linux_kernel)]
- pub const CRYPTO: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_CRYPTO as _) });
+ pub const CRYPTO: Protocol = Protocol(new_raw_protocol(c::NETLINK_CRYPTO as _));
/// `NETLINK_INET_DIAG`
#[cfg(linux_kernel)]
- pub const INET_DIAG: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_INET_DIAG as _) });
+ pub const INET_DIAG: Protocol = Protocol(new_raw_protocol(c::NETLINK_INET_DIAG as _));
/// `NETLINK_ADD_MEMBERSHIP`
#[cfg(linux_kernel)]
- pub const ADD_MEMBERSHIP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_ADD_MEMBERSHIP as _) });
+ pub const ADD_MEMBERSHIP: Protocol = Protocol(new_raw_protocol(c::NETLINK_ADD_MEMBERSHIP as _));
/// `NETLINK_DROP_MEMBERSHIP`
#[cfg(linux_kernel)]
pub const DROP_MEMBERSHIP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_DROP_MEMBERSHIP as _) });
+ Protocol(new_raw_protocol(c::NETLINK_DROP_MEMBERSHIP as _));
/// `NETLINK_PKTINFO`
#[cfg(linux_kernel)]
- pub const PKTINFO: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_PKTINFO as _) });
+ pub const PKTINFO: Protocol = Protocol(new_raw_protocol(c::NETLINK_PKTINFO as _));
/// `NETLINK_BROADCAST_ERROR`
#[cfg(linux_kernel)]
pub const BROADCAST_ERROR: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_BROADCAST_ERROR as _) });
+ Protocol(new_raw_protocol(c::NETLINK_BROADCAST_ERROR as _));
/// `NETLINK_NO_ENOBUFS`
#[cfg(linux_kernel)]
- pub const NO_ENOBUFS: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_NO_ENOBUFS as _) });
+ pub const NO_ENOBUFS: Protocol = Protocol(new_raw_protocol(c::NETLINK_NO_ENOBUFS as _));
/// `NETLINK_RX_RING`
#[cfg(linux_kernel)]
- pub const RX_RING: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_RX_RING as _) });
+ pub const RX_RING: Protocol = Protocol(new_raw_protocol(c::NETLINK_RX_RING as _));
/// `NETLINK_TX_RING`
#[cfg(linux_kernel)]
- pub const TX_RING: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_TX_RING as _) });
+ pub const TX_RING: Protocol = Protocol(new_raw_protocol(c::NETLINK_TX_RING as _));
/// `NETLINK_LISTEN_ALL_NSID`
#[cfg(linux_kernel)]
pub const LISTEN_ALL_NSID: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_LISTEN_ALL_NSID as _) });
+ Protocol(new_raw_protocol(c::NETLINK_LISTEN_ALL_NSID as _));
/// `NETLINK_LIST_MEMBERSHIPS`
#[cfg(linux_kernel)]
pub const LIST_MEMBERSHIPS: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_LIST_MEMBERSHIPS as _) });
+ Protocol(new_raw_protocol(c::NETLINK_LIST_MEMBERSHIPS as _));
/// `NETLINK_CAP_ACK`
#[cfg(linux_kernel)]
- pub const CAP_ACK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_CAP_ACK as _) });
+ pub const CAP_ACK: Protocol = Protocol(new_raw_protocol(c::NETLINK_CAP_ACK as _));
/// `NETLINK_EXT_ACK`
#[cfg(linux_kernel)]
- pub const EXT_ACK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_EXT_ACK as _) });
+ pub const EXT_ACK: Protocol = Protocol(new_raw_protocol(c::NETLINK_EXT_ACK as _));
/// `NETLINK_GET_STRICT_CHK`
#[cfg(linux_kernel)]
- pub const GET_STRICT_CHK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked(c::NETLINK_GET_STRICT_CHK as _) });
+ pub const GET_STRICT_CHK: Protocol = Protocol(new_raw_protocol(c::NETLINK_GET_STRICT_CHK as _));
}
/// `ETH_P_*` constants.
-///
// These are translated into 16-bit big-endian form because that's what the
-// `AddressFamily::PACKET` address family [expects].
+// [`AddressFamily::PACKET`] address family [expects].
//
// [expects]: https://man7.org/linux/man-pages/man7/packet.7.html
pub mod eth {
#[cfg(linux_kernel)]
use {
- super::{Protocol, RawProtocol},
+ super::{new_raw_protocol, Protocol},
crate::backend::c,
};
/// `ETH_P_LOOP`
#[cfg(linux_kernel)]
- pub const LOOP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LOOP as u16).to_be() as u32) });
+ pub const LOOP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LOOP as u16).to_be() as u32));
/// `ETH_P_PUP`
#[cfg(linux_kernel)]
- pub const PUP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PUP as u16).to_be() as u32) });
+ pub const PUP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUP as u16).to_be() as u32));
/// `ETH_P_PUPAT`
#[cfg(linux_kernel)]
- pub const PUPAT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PUPAT as u16).to_be() as u32) });
+ pub const PUPAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUPAT as u16).to_be() as u32));
/// `ETH_P_TSN`
#[cfg(linux_kernel)]
- pub const TSN: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TSN as u16).to_be() as u32) });
+ pub const TSN: Protocol = Protocol(new_raw_protocol((c::ETH_P_TSN as u16).to_be() as u32));
/// `ETH_P_ERSPAN2`
#[cfg(linux_kernel)]
pub const ERSPAN2: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ERSPAN2 as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ERSPAN2 as u16).to_be() as u32));
/// `ETH_P_IP`
#[cfg(linux_kernel)]
- pub const IP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IP as u16).to_be() as u32) });
+ pub const IP: Protocol = Protocol(new_raw_protocol((c::ETH_P_IP as u16).to_be() as u32));
/// `ETH_P_X25`
#[cfg(linux_kernel)]
- pub const X25: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_X25 as u16).to_be() as u32) });
+ pub const X25: Protocol = Protocol(new_raw_protocol((c::ETH_P_X25 as u16).to_be() as u32));
/// `ETH_P_ARP`
#[cfg(linux_kernel)]
- pub const ARP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ARP as u16).to_be() as u32) });
+ pub const ARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_ARP as u16).to_be() as u32));
/// `ETH_P_BPQ`
#[cfg(linux_kernel)]
- pub const BPQ: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_BPQ as u16).to_be() as u32) });
+ pub const BPQ: Protocol = Protocol(new_raw_protocol((c::ETH_P_BPQ as u16).to_be() as u32));
/// `ETH_P_IEEEPUP`
#[cfg(linux_kernel)]
pub const IEEEPUP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IEEEPUP as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_IEEEPUP as u16).to_be() as u32));
/// `ETH_P_IEEEPUPAT`
#[cfg(linux_kernel)]
pub const IEEEPUPAT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IEEEPUPAT as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_IEEEPUPAT as u16).to_be() as u32));
/// `ETH_P_BATMAN`
#[cfg(linux_kernel)]
pub const BATMAN: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_BATMAN as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_BATMAN as u16).to_be() as u32));
/// `ETH_P_DEC`
#[cfg(linux_kernel)]
- pub const DEC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DEC as u16).to_be() as u32) });
+ pub const DEC: Protocol = Protocol(new_raw_protocol((c::ETH_P_DEC as u16).to_be() as u32));
/// `ETH_P_DNA_DL`
#[cfg(linux_kernel)]
pub const DNA_DL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DNA_DL as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_DNA_DL as u16).to_be() as u32));
/// `ETH_P_DNA_RC`
#[cfg(linux_kernel)]
pub const DNA_RC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DNA_RC as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_DNA_RC as u16).to_be() as u32));
/// `ETH_P_DNA_RT`
#[cfg(linux_kernel)]
pub const DNA_RT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DNA_RT as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_DNA_RT as u16).to_be() as u32));
/// `ETH_P_LAT`
#[cfg(linux_kernel)]
- pub const LAT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LAT as u16).to_be() as u32) });
+ pub const LAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_LAT as u16).to_be() as u32));
/// `ETH_P_DIAG`
#[cfg(linux_kernel)]
- pub const DIAG: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DIAG as u16).to_be() as u32) });
+ pub const DIAG: Protocol = Protocol(new_raw_protocol((c::ETH_P_DIAG as u16).to_be() as u32));
/// `ETH_P_CUST`
#[cfg(linux_kernel)]
- pub const CUST: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CUST as u16).to_be() as u32) });
+ pub const CUST: Protocol = Protocol(new_raw_protocol((c::ETH_P_CUST as u16).to_be() as u32));
/// `ETH_P_SCA`
#[cfg(linux_kernel)]
- pub const SCA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_SCA as u16).to_be() as u32) });
+ pub const SCA: Protocol = Protocol(new_raw_protocol((c::ETH_P_SCA as u16).to_be() as u32));
/// `ETH_P_TEB`
#[cfg(linux_kernel)]
- pub const TEB: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TEB as u16).to_be() as u32) });
+ pub const TEB: Protocol = Protocol(new_raw_protocol((c::ETH_P_TEB as u16).to_be() as u32));
/// `ETH_P_RARP`
#[cfg(linux_kernel)]
- pub const RARP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_RARP as u16).to_be() as u32) });
+ pub const RARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_RARP as u16).to_be() as u32));
/// `ETH_P_ATALK`
#[cfg(linux_kernel)]
- pub const ATALK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ATALK as u16).to_be() as u32) });
+ pub const ATALK: Protocol = Protocol(new_raw_protocol((c::ETH_P_ATALK as u16).to_be() as u32));
/// `ETH_P_AARP`
#[cfg(linux_kernel)]
- pub const AARP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AARP as u16).to_be() as u32) });
+ pub const AARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_AARP as u16).to_be() as u32));
/// `ETH_P_8021Q`
#[cfg(linux_kernel)]
pub const P_8021Q: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_8021Q as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_8021Q as u16).to_be() as u32));
/// `ETH_P_ERSPAN`
#[cfg(linux_kernel)]
pub const ERSPAN: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ERSPAN as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ERSPAN as u16).to_be() as u32));
/// `ETH_P_IPX`
#[cfg(linux_kernel)]
- pub const IPX: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IPX as u16).to_be() as u32) });
+ pub const IPX: Protocol = Protocol(new_raw_protocol((c::ETH_P_IPX as u16).to_be() as u32));
/// `ETH_P_IPV6`
#[cfg(linux_kernel)]
- pub const IPV6: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IPV6 as u16).to_be() as u32) });
+ pub const IPV6: Protocol = Protocol(new_raw_protocol((c::ETH_P_IPV6 as u16).to_be() as u32));
/// `ETH_P_PAUSE`
#[cfg(linux_kernel)]
- pub const PAUSE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PAUSE as u16).to_be() as u32) });
+ pub const PAUSE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAUSE as u16).to_be() as u32));
/// `ETH_P_SLOW`
#[cfg(linux_kernel)]
- pub const SLOW: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_SLOW as u16).to_be() as u32) });
+ pub const SLOW: Protocol = Protocol(new_raw_protocol((c::ETH_P_SLOW as u16).to_be() as u32));
/// `ETH_P_WCCP`
#[cfg(linux_kernel)]
- pub const WCCP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_WCCP as u16).to_be() as u32) });
+ pub const WCCP: Protocol = Protocol(new_raw_protocol((c::ETH_P_WCCP as u16).to_be() as u32));
/// `ETH_P_MPLS_UC`
#[cfg(linux_kernel)]
pub const MPLS_UC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MPLS_UC as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_MPLS_UC as u16).to_be() as u32));
/// `ETH_P_MPLS_MC`
#[cfg(linux_kernel)]
pub const MPLS_MC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MPLS_MC as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_MPLS_MC as u16).to_be() as u32));
/// `ETH_P_ATMMPOA`
#[cfg(linux_kernel)]
pub const ATMMPOA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ATMMPOA as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ATMMPOA as u16).to_be() as u32));
/// `ETH_P_PPP_DISC`
#[cfg(linux_kernel)]
pub const PPP_DISC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPP_DISC as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PPP_DISC as u16).to_be() as u32));
/// `ETH_P_PPP_SES`
#[cfg(linux_kernel)]
pub const PPP_SES: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPP_SES as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PPP_SES as u16).to_be() as u32));
/// `ETH_P_LINK_CTL`
#[cfg(linux_kernel)]
pub const LINK_CTL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LINK_CTL as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_LINK_CTL as u16).to_be() as u32));
/// `ETH_P_ATMFATE`
#[cfg(linux_kernel)]
pub const ATMFATE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ATMFATE as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ATMFATE as u16).to_be() as u32));
/// `ETH_P_PAE`
#[cfg(linux_kernel)]
- pub const PAE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PAE as u16).to_be() as u32) });
+ pub const PAE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAE as u16).to_be() as u32));
/// `ETH_P_PROFINET`
#[cfg(linux_kernel)]
pub const PROFINET: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PROFINET as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PROFINET as u16).to_be() as u32));
/// `ETH_P_REALTEK`
#[cfg(linux_kernel)]
pub const REALTEK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_REALTEK as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_REALTEK as u16).to_be() as u32));
/// `ETH_P_AOE`
#[cfg(linux_kernel)]
- pub const AOE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AOE as u16).to_be() as u32) });
+ pub const AOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_AOE as u16).to_be() as u32));
/// `ETH_P_ETHERCAT`
#[cfg(linux_kernel)]
pub const ETHERCAT: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ETHERCAT as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ETHERCAT as u16).to_be() as u32));
/// `ETH_P_8021AD`
#[cfg(linux_kernel)]
pub const P_8021AD: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_8021AD as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_8021AD as u16).to_be() as u32));
/// `ETH_P_802_EX1`
#[cfg(linux_kernel)]
pub const P_802_EX1: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_EX1 as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_802_EX1 as u16).to_be() as u32));
/// `ETH_P_PREAUTH`
#[cfg(linux_kernel)]
pub const PREAUTH: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PREAUTH as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PREAUTH as u16).to_be() as u32));
/// `ETH_P_TIPC`
#[cfg(linux_kernel)]
- pub const TIPC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TIPC as u16).to_be() as u32) });
+ pub const TIPC: Protocol = Protocol(new_raw_protocol((c::ETH_P_TIPC as u16).to_be() as u32));
/// `ETH_P_LLDP`
#[cfg(linux_kernel)]
- pub const LLDP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LLDP as u16).to_be() as u32) });
+ pub const LLDP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LLDP as u16).to_be() as u32));
/// `ETH_P_MRP`
#[cfg(linux_kernel)]
- pub const MRP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MRP as u16).to_be() as u32) });
+ pub const MRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MRP as u16).to_be() as u32));
/// `ETH_P_MACSEC`
#[cfg(linux_kernel)]
pub const MACSEC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MACSEC as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_MACSEC as u16).to_be() as u32));
/// `ETH_P_8021AH`
#[cfg(linux_kernel)]
pub const P_8021AH: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_8021AH as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_8021AH as u16).to_be() as u32));
/// `ETH_P_MVRP`
#[cfg(linux_kernel)]
- pub const MVRP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MVRP as u16).to_be() as u32) });
+ pub const MVRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MVRP as u16).to_be() as u32));
/// `ETH_P_1588`
#[cfg(linux_kernel)]
- pub const P_1588: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_1588 as u16).to_be() as u32) });
+ pub const P_1588: Protocol = Protocol(new_raw_protocol((c::ETH_P_1588 as u16).to_be() as u32));
/// `ETH_P_NCSI`
#[cfg(linux_kernel)]
- pub const NCSI: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_NCSI as u16).to_be() as u32) });
+ pub const NCSI: Protocol = Protocol(new_raw_protocol((c::ETH_P_NCSI as u16).to_be() as u32));
/// `ETH_P_PRP`
#[cfg(linux_kernel)]
- pub const PRP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PRP as u16).to_be() as u32) });
+ pub const PRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PRP as u16).to_be() as u32));
/// `ETH_P_CFM`
#[cfg(linux_kernel)]
- pub const CFM: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CFM as u16).to_be() as u32) });
+ pub const CFM: Protocol = Protocol(new_raw_protocol((c::ETH_P_CFM as u16).to_be() as u32));
/// `ETH_P_FCOE`
#[cfg(linux_kernel)]
- pub const FCOE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_FCOE as u16).to_be() as u32) });
+ pub const FCOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_FCOE as u16).to_be() as u32));
/// `ETH_P_IBOE`
#[cfg(linux_kernel)]
- pub const IBOE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IBOE as u16).to_be() as u32) });
+ pub const IBOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IBOE as u16).to_be() as u32));
/// `ETH_P_TDLS`
#[cfg(linux_kernel)]
- pub const TDLS: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TDLS as u16).to_be() as u32) });
+ pub const TDLS: Protocol = Protocol(new_raw_protocol((c::ETH_P_TDLS as u16).to_be() as u32));
/// `ETH_P_FIP`
#[cfg(linux_kernel)]
- pub const FIP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_FIP as u16).to_be() as u32) });
+ pub const FIP: Protocol = Protocol(new_raw_protocol((c::ETH_P_FIP as u16).to_be() as u32));
/// `ETH_P_80221`
#[cfg(linux_kernel)]
pub const P_80221: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_80221 as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_80221 as u16).to_be() as u32));
/// `ETH_P_HSR`
#[cfg(linux_kernel)]
- pub const HSR: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_HSR as u16).to_be() as u32) });
+ pub const HSR: Protocol = Protocol(new_raw_protocol((c::ETH_P_HSR as u16).to_be() as u32));
/// `ETH_P_NSH`
#[cfg(linux_kernel)]
- pub const NSH: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_NSH as u16).to_be() as u32) });
+ pub const NSH: Protocol = Protocol(new_raw_protocol((c::ETH_P_NSH as u16).to_be() as u32));
/// `ETH_P_LOOPBACK`
#[cfg(linux_kernel)]
pub const LOOPBACK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LOOPBACK as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_LOOPBACK as u16).to_be() as u32));
/// `ETH_P_QINQ1`
#[cfg(linux_kernel)]
- pub const QINQ1: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_QINQ1 as u16).to_be() as u32) });
+ pub const QINQ1: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ1 as u16).to_be() as u32));
/// `ETH_P_QINQ2`
#[cfg(linux_kernel)]
- pub const QINQ2: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_QINQ2 as u16).to_be() as u32) });
+ pub const QINQ2: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ2 as u16).to_be() as u32));
/// `ETH_P_QINQ3`
#[cfg(linux_kernel)]
- pub const QINQ3: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_QINQ3 as u16).to_be() as u32) });
+ pub const QINQ3: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ3 as u16).to_be() as u32));
/// `ETH_P_EDSA`
#[cfg(linux_kernel)]
- pub const EDSA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_EDSA as u16).to_be() as u32) });
+ pub const EDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_EDSA as u16).to_be() as u32));
/// `ETH_P_DSA_8021Q`
#[cfg(linux_kernel)]
pub const DSA_8021Q: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DSA_8021Q as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_DSA_8021Q as u16).to_be() as u32));
/// `ETH_P_DSA_A5PSW`
#[cfg(linux_kernel)]
pub const DSA_A5PSW: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DSA_A5PSW as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_DSA_A5PSW as u16).to_be() as u32));
/// `ETH_P_IFE`
#[cfg(linux_kernel)]
- pub const IFE: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IFE as u16).to_be() as u32) });
+ pub const IFE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IFE as u16).to_be() as u32));
/// `ETH_P_AF_IUCV`
#[cfg(linux_kernel)]
pub const AF_IUCV: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AF_IUCV as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_AF_IUCV as u16).to_be() as u32));
/// `ETH_P_802_3_MIN`
#[cfg(linux_kernel)]
pub const P_802_3_MIN: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_3_MIN as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_802_3_MIN as u16).to_be() as u32));
/// `ETH_P_802_3`
#[cfg(linux_kernel)]
pub const P_802_3: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_3 as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_802_3 as u16).to_be() as u32));
/// `ETH_P_AX25`
#[cfg(linux_kernel)]
- pub const AX25: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_AX25 as u16).to_be() as u32) });
+ pub const AX25: Protocol = Protocol(new_raw_protocol((c::ETH_P_AX25 as u16).to_be() as u32));
/// `ETH_P_ALL`
#[cfg(linux_kernel)]
- pub const ALL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ALL as u16).to_be() as u32) });
+ pub const ALL: Protocol = Protocol(new_raw_protocol((c::ETH_P_ALL as u16).to_be() as u32));
/// `ETH_P_802_2`
#[cfg(linux_kernel)]
pub const P_802_2: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_802_2 as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_802_2 as u16).to_be() as u32));
/// `ETH_P_SNAP`
#[cfg(linux_kernel)]
- pub const SNAP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_SNAP as u16).to_be() as u32) });
+ pub const SNAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_SNAP as u16).to_be() as u32));
/// `ETH_P_DDCMP`
#[cfg(linux_kernel)]
- pub const DDCMP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DDCMP as u16).to_be() as u32) });
+ pub const DDCMP: Protocol = Protocol(new_raw_protocol((c::ETH_P_DDCMP as u16).to_be() as u32));
/// `ETH_P_WAN_PPP`
#[cfg(linux_kernel)]
pub const WAN_PPP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_WAN_PPP as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_WAN_PPP as u16).to_be() as u32));
/// `ETH_P_PPP_MP`
#[cfg(linux_kernel)]
pub const PPP_MP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPP_MP as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PPP_MP as u16).to_be() as u32));
/// `ETH_P_LOCALTALK`
#[cfg(linux_kernel)]
pub const LOCALTALK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_LOCALTALK as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_LOCALTALK as u16).to_be() as u32));
/// `ETH_P_CAN`
#[cfg(linux_kernel)]
- pub const CAN: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CAN as u16).to_be() as u32) });
+ pub const CAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAN as u16).to_be() as u32));
/// `ETH_P_CANFD`
#[cfg(linux_kernel)]
- pub const CANFD: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CANFD as u16).to_be() as u32) });
+ pub const CANFD: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANFD as u16).to_be() as u32));
/// `ETH_P_CANXL`
#[cfg(linux_kernel)]
- pub const CANXL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CANXL as u16).to_be() as u32) });
+ pub const CANXL: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANXL as u16).to_be() as u32));
/// `ETH_P_PPPTALK`
#[cfg(linux_kernel)]
pub const PPPTALK: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PPPTALK as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PPPTALK as u16).to_be() as u32));
/// `ETH_P_TR_802_2`
#[cfg(linux_kernel)]
pub const TR_802_2: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TR_802_2 as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_TR_802_2 as u16).to_be() as u32));
/// `ETH_P_MOBITEX`
#[cfg(linux_kernel)]
pub const MOBITEX: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MOBITEX as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_MOBITEX as u16).to_be() as u32));
/// `ETH_P_CONTROL`
#[cfg(linux_kernel)]
pub const CONTROL: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CONTROL as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_CONTROL as u16).to_be() as u32));
/// `ETH_P_IRDA`
#[cfg(linux_kernel)]
- pub const IRDA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_IRDA as u16).to_be() as u32) });
+ pub const IRDA: Protocol = Protocol(new_raw_protocol((c::ETH_P_IRDA as u16).to_be() as u32));
/// `ETH_P_ECONET`
#[cfg(linux_kernel)]
pub const ECONET: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ECONET as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ECONET as u16).to_be() as u32));
/// `ETH_P_HDLC`
#[cfg(linux_kernel)]
- pub const HDLC: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_HDLC as u16).to_be() as u32) });
+ pub const HDLC: Protocol = Protocol(new_raw_protocol((c::ETH_P_HDLC as u16).to_be() as u32));
/// `ETH_P_ARCNET`
#[cfg(linux_kernel)]
pub const ARCNET: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_ARCNET as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_ARCNET as u16).to_be() as u32));
/// `ETH_P_DSA`
#[cfg(linux_kernel)]
- pub const DSA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_DSA as u16).to_be() as u32) });
+ pub const DSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA as u16).to_be() as u32));
/// `ETH_P_TRAILER`
#[cfg(linux_kernel)]
pub const TRAILER: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_TRAILER as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_TRAILER as u16).to_be() as u32));
/// `ETH_P_PHONET`
#[cfg(linux_kernel)]
pub const PHONET: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_PHONET as u16).to_be() as u32) });
+ Protocol(new_raw_protocol((c::ETH_P_PHONET as u16).to_be() as u32));
/// `ETH_P_IEEE802154`
#[cfg(linux_kernel)]
- pub const IEEE802154: Protocol = Protocol(unsafe {
- RawProtocol::new_unchecked((c::ETH_P_IEEE802154 as u16).to_be() as u32)
- });
+ pub const IEEE802154: Protocol =
+ Protocol(new_raw_protocol((c::ETH_P_IEEE802154 as u16).to_be() as u32));
/// `ETH_P_CAIF`
#[cfg(linux_kernel)]
- pub const CAIF: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_CAIF as u16).to_be() as u32) });
+ pub const CAIF: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAIF as u16).to_be() as u32));
/// `ETH_P_XDSA`
#[cfg(linux_kernel)]
- pub const XDSA: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_XDSA as u16).to_be() as u32) });
+ pub const XDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_XDSA as u16).to_be() as u32));
/// `ETH_P_MAP`
#[cfg(linux_kernel)]
- pub const MAP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MAP as u16).to_be() as u32) });
+ pub const MAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MAP as u16).to_be() as u32));
/// `ETH_P_MCTP`
#[cfg(linux_kernel)]
- pub const MCTP: Protocol =
- Protocol(unsafe { RawProtocol::new_unchecked((c::ETH_P_MCTP as u16).to_be() as u32) });
+ pub const MCTP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MCTP as u16).to_be() as u32));
}
#[rustfmt::skip]
@@ -1361,12 +1316,23 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct SocketFlags: c::c_uint {
/// `SOCK_NONBLOCK`
- #[cfg(not(any(apple, windows, target_os = "espidf", target_os = "haiku", target_os = "nto")))]
+ #[cfg(not(any(
+ apple,
+ windows,
+ target_os = "aix",
+ target_os = "espidf",
+ target_os = "haiku",
+ target_os = "nto",
+ )))]
const NONBLOCK = bitcast!(c::SOCK_NONBLOCK);
/// `SOCK_CLOEXEC`
- #[cfg(not(any(apple, windows, target_os = "haiku")))]
+ #[cfg(not(any(apple, windows, target_os = "aix", target_os = "haiku")))]
const CLOEXEC = bitcast!(c::SOCK_CLOEXEC);
+
+ // This deliberately lacks a `const _ = !0`, so that users can use
+ // `from_bits_truncate` to extract the `SocketFlags` from a flags
+ // value that also includes a `SocketType`.
}
}
@@ -1375,8 +1341,8 @@ fn test_sizes() {
use c::c_int;
use core::mem::transmute;
- // Backend code needs to cast these to `c_int` so make sure that cast
- // isn't lossy.
+ // Backend code needs to cast these to `c_int` so make sure that cast isn't
+ // lossy.
assert_eq_size!(RawProtocol, c_int);
assert_eq_size!(Protocol, c_int);
assert_eq_size!(Option<RawProtocol>, c_int);
@@ -1385,13 +1351,14 @@ fn test_sizes() {
assert_eq_size!(SocketType, c_int);
assert_eq_size!(SocketFlags, c_int);
- // Rustix doesn't depend on `Option<Protocol>` matching the ABI of
- // a raw integer for correctness, but it should work nonetheless.
+ // Rustix doesn't depend on `Option<Protocol>` matching the ABI of a raw
+ // integer for correctness, but it should work nonetheless.
+ #[allow(unsafe_code)]
unsafe {
let t: Option<Protocol> = None;
- assert_eq!(0_u32, transmute(t));
+ assert_eq!(0_u32, transmute::<Option<Protocol>, u32>(t));
let t: Option<Protocol> = Some(Protocol::from_raw(RawProtocol::new(4567).unwrap()));
- assert_eq!(4567_u32, transmute(t));
+ assert_eq!(4567_u32, transmute::<Option<Protocol>, u32>(t));
}
}