move sys_socket bits from C to cbindgen

This commit is contained in:
auronandace
2026-04-13 10:18:40 +01:00
parent de0f2f5329
commit e8429cdc5e
3 changed files with 33 additions and 31 deletions
+8 -2
View File
@@ -76,8 +76,10 @@ pub struct sockaddr {
}
// Max size of [`sockaddr_storage`]
/// cbindgen:ignore
const _SS_MAXSIZE: usize = 128;
// Align to pointer width
/// cbindgen:ignore
const _SS_PADDING: usize = _SS_MAXSIZE - mem::size_of::<sa_family_t>() - mem::size_of::<usize>();
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_socket.h.html>.
@@ -91,22 +93,26 @@ const _SS_PADDING: usize = _SS_MAXSIZE - mem::size_of::<sa_family_t>() - mem::si
/// from protocol structs in C
#[repr(C)]
//#[derive(CheckVsLibcCrate)] FIXME: can't ignore private fields yet
/// cbindgen:ignore
pub struct sockaddr_storage {
pub ss_family: sa_family_t,
__ss_pad2: [u8; _SS_PADDING],
__ss_align: usize,
}
// These must match C macros in include/bits/sys/socket.h {
// These must match C macros in sys_socket/cbindgen.toml {
/// cbindgen:ignore
pub unsafe extern "C" fn __CMSG_LEN(cmsg: *const cmsghdr) -> ssize_t {
((unsafe { (*cmsg).cmsg_len as size_t } + mem::size_of::<c_long>() - 1)
& !(mem::size_of::<c_long>() - 1)) as ssize_t
}
/// cbindgen:ignore
pub unsafe extern "C" fn __CMSG_NEXT(cmsg: *const cmsghdr) -> *mut c_uchar {
unsafe { (cmsg as *mut c_uchar).offset(__CMSG_LEN(cmsg)) }
}
/// cbindgen:ignore
pub unsafe extern "C" fn __MHDR_END(mhdr: *const msghdr) -> *mut c_uchar {
unsafe { ((*mhdr).msg_control.cast::<c_uchar>()).add((*mhdr).msg_controllen) }
}
@@ -165,7 +171,7 @@ pub unsafe extern "C" fn CMSG_SPACE(len: c_uint) -> c_uint {
pub unsafe extern "C" fn CMSG_LEN(length: c_uint) -> c_uint {
(unsafe { CMSG_ALIGN(mem::size_of::<cmsghdr>()) } + length as usize) as c_uint
}
// } These must match C macros in include/bits/sys/socket.h
// } These must match C macros in sys_socket/cbindgen.toml
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/accept.html>.
#[unsafe(no_mangle)]