nc/platform/linux-types/uapi/linux/socket.rs
1// Copyright (c) 2020 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License that can be found
3// in the LICENSE file.
4
5//! From `include/uapi/linux/socket.h`
6
7use core::fmt;
8
9/// Desired design of maximum size and alignment (see RFC2553)
10/// Implementation specific max size
11const K_SS_MAXSIZE: i32 = 128;
12
13/* Implementation specific desired alignment */
14//pub const _K_SS_ALIGNSIZE: i32 =(__alignof__ (struct sockaddr *))
15
16pub type kernel_sa_family_t = u16;
17
18#[repr(C)]
19#[derive(Clone)]
20pub struct kernel_sockaddr_storage_t {
21 /// address family
22 pub ss_family: kernel_sa_family_t,
23 /// Following field(s) are implementation specific
24 /// space to achieve desired size,
25 /// _`SS_MAXSIZE` value minus size of `ss_family`
26 pub data: [u8; (K_SS_MAXSIZE - 2) as usize],
27}
28
29// TODO(Shaohua):
30//__attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */
31impl Default for kernel_sockaddr_storage_t {
32 fn default() -> Self {
33 Self {
34 ss_family: 0,
35 data: [0_u8; (K_SS_MAXSIZE - 2) as usize],
36 }
37 }
38}
39
40impl fmt::Debug for kernel_sockaddr_storage_t {
41 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42 f.debug_struct("kernel_sockaddr_storage_t")
43 .field("ss_family", &self.ss_family)
44 .field("data", &&self.data[0..32])
45 .finish()
46 }
47}