From 73c243700c2cca44f6334b8ddb56b794c064d12f Mon Sep 17 00:00:00 2001 From: Matthew McPherrin <git@mcpherrin.ca> Date: Sun, 1 Dec 2019 19:46:05 -0800 Subject: [PATCH] Add sock_extended_err and associated constants from errqueue.h sock_extended_err is a struct returned as a control message when the sockopt IP_RECVERR is set, when recvmsg has the MSG_ERRQUEUE flag set. IP_RECVERR and MSG_ERRQUEUE are constants both already defined here. --- libc-test/build.rs | 1 + src/unix/linux_like/mod.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 824bae5d..4f8cf70a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2189,6 +2189,7 @@ fn test_linux(target: &str) { cfg: "asm/mman.h", "linux/dccp.h", + "linux/errqueue.h", "linux/falloc.h", "linux/fs.h", "linux/futex.h", diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index 792548f9..5b2fb11c 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -199,6 +199,16 @@ s! { pub msg_hdr: ::msghdr, pub msg_len: ::c_uint, } + + pub struct sock_extended_err { + pub ee_errno: u32, + pub ee_origin: u8, + pub ee_type: u8, + pub ee_code: u8, + pub ee_pad: u8, + pub ee_info: u32, + pub ee_data: u32 + } } s_no_extra_traits! { @@ -1189,6 +1199,13 @@ pub const ARPHRD_IEEE802154: u16 = 804; pub const ARPHRD_VOID: u16 = 0xFFFF; pub const ARPHRD_NONE: u16 = 0xFFFE; +pub const SO_EE_ORIGIN_NONE: u8 = 0; +pub const SO_EE_ORIGIN_LOCAL: u8 = 1; +pub const SO_EE_ORIGIN_ICMP: u8 = 2; +pub const SO_EE_ORIGIN_ICMP6: u8 = 3; +pub const SO_EE_ORIGIN_TXSTATUS: u8 = 4; +pub const SO_EE_ORIGIN_TIMESTAMPING: u8 = SO_EE_ORIGIN_TXSTATUS; + const_fn! { {const} fn CMSG_ALIGN(len: usize) -> usize { len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1) @@ -1294,6 +1311,10 @@ f! { pub fn IPTOS_ECN(x: u8) -> u8 { x & ::IPTOS_ECN_MASK } + + pub fn SO_EE_OFFENDER(ee: *const ::sock_extended_err) -> *mut ::sockaddr { + ee.offset(1) as *mut ::sockaddr + } } extern "C" { -- GitLab