libdlpi_sys/
lib.rs

1#![allow(non_camel_case_types)]
2
3use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_void};
4
5/// Maximum size for a physical address.
6pub const DLPI_PHYSADDR_MAX: usize = 64;
7
8/// DLPI Flags
9
10/// Exclusive open.
11pub const DLPI_EXCL: c_uint = 0x0001;
12/// Open DLPI link in passive mode.
13pub const DLPI_PASSIVE: c_uint = 0x0002;
14/// Open DLPI link in raw mode.
15pub const DLPI_RAW: c_uint = 0x0004;
16/// Synchronous serial line interface.
17pub const DLPI_SERIAL: c_uint = 0x0008;
18/// Do not attach PPA.
19pub const DLPI_NOATTACH: c_uint = 0x0010;
20/// Open DLPI link in native mode.
21pub const DLPI_NATIVE: c_uint = 0x0020;
22/// Open DLPI link under /dev only.
23pub const DLPI_DEVONLY: c_uint = 0x0040;
24/// Open IP DLPI link under /dev/ipnet.
25pub const DLPI_DEVIPNET: c_uint = 0x0080;
26/// Request ipnetinfo headers.
27pub const DLPI_IPNETINFO: c_uint = 0x0100;
28/// Promiscuous mode at the phys level
29pub const DL_PROMISC_PHYS: c_uint = 0x01;
30/// Promiscuous mode at the sap level
31pub const DL_PROMISC_SAP: c_uint = 0x02;
32/// Promiscuous mode for multicast
33pub const DL_PROMISC_MULTI: c_uint = 0x03;
34/// Promiscuous mode for rx only
35pub const DL_PROMISC_RX_ONLY: c_uint = 0x04;
36
37/// DLPI operation succeeded
38pub const DLPI_SUCCESS: c_int = 10000;
39/// invalid argument
40pub const DLPI_EINVAL: c_int = 10001;
41/// invalid DLPI linkname
42pub const DLPI_ELINKNAMEINVAL: c_int = 10002;
43/// DLPI link does not exist
44pub const DLPI_ENOLINK: c_int = 10003;
45/// bad DLPI link
46pub const DLPI_EBADLINK: c_int = 10004;
47/// invalid DLPI handle
48pub const DLPI_EINHANDLE: c_int = 10005;
49/// DLPI operation timed out
50pub const DLPI_ETIMEDOUT: c_int = 10006;
51/// unsupported DLPI Version
52pub const DLPI_EVERNOTSUP: c_int = 10007;
53/// unsupported DLPI connection mode
54pub const DLPI_EMODENOTSUP: c_int = 10008;
55/// unavailable DLPI SAP
56pub const DLPI_EUNAVAILSAP: c_int = 10009;
57/// DLPI operation failed
58pub const DLPI_FAILURE: c_int = 10010;
59/// DLPI style-2 node reports style-1
60pub const DLPI_ENOTSTYLE2: c_int = 10011;
61/// bad DLPI message
62pub const DLPI_EBADMSG: c_int = 10012;
63/// DLPI raw mode not supported
64pub const DLPI_ERAWNOTSUP: c_int = 10013;
65/// invalid DLPI notification type
66pub const DLPI_ENOTEINVAL: c_int = 10014;
67/// DLPI notif. not supported by link
68pub const DLPI_ENOTENOTSUP: c_int = 10015;
69/// invalid DLPI notification id
70pub const DLPI_ENOTEIDINVAL: c_int = 10016;
71/// DLPI_IPNETINFO not supported
72pub const DLPI_EIPNETINFONOTSUP: c_int = 10017;
73
74/// Information used to send DLPI traffic.
75#[repr(C)]
76#[derive(Debug)]
77pub struct dlpi_sendinfo_t {
78    /// Service access point to use. For ethernet, this is the ethertype.
79    pub dsi_sap: c_uint,
80    /// Range spans from 0 to 100 where 0 is the highest.
81    pub dsi_prio: dl_priority_t,
82}
83
84/// Information from received DLPI traffic.
85#[repr(C)]
86pub struct dlpi_recvinfo_t {
87    pub dri_destaddr: [c_uchar; DLPI_PHYSADDR_MAX],
88    pub dri_destaddrlen: c_uchar,
89    pub dri_destaddrtype: dlpi_addrtype_t,
90    pub dri_totmsglen: usize,
91}
92
93impl Default for dlpi_recvinfo_t {
94    fn default() -> Self {
95        dlpi_recvinfo_t {
96            dri_destaddr: [0; DLPI_PHYSADDR_MAX],
97            dri_destaddrlen: 0,
98            dri_destaddrtype: dlpi_addrtype_t::DLPI_ADDRTYPE_UNICAST,
99            dri_totmsglen: 0,
100        }
101    }
102}
103
104/// Indicates if an address is unicast or not.
105#[repr(C)]
106pub enum dlpi_addrtype_t {
107    DLPI_ADDRTYPE_UNICAST,
108    DLPI_ADDRTYPE_GROUP,
109}
110
111/// Defines priority for DLPI traffic sent.
112#[repr(C)]
113#[derive(Debug)]
114pub struct dl_priority_t {
115    pub dl_min: u32,
116    pub dl_max: u32,
117}
118
119/// Indicates a non-DLPI specific system error in a DLPI call.
120pub const DL_SYSERR: c_int = 0x04;
121
122/// Opaque handle to a DLPI link instance.
123#[derive(Clone)]
124pub enum dlpi_handle_t {}
125unsafe impl Send for dlpi_handle_t {}
126unsafe impl Sync for dlpi_handle_t {}
127
128extern "C" {
129    /// Creates an instance of the DLPI version 2 link named by linnkname.
130    ///
131    /// Associates with it a dynamically-allocated dlpi_handle_t, which is
132    /// returend to the caller upon success. This handle is used in other DLPI
133    /// function calls for sending and receiving traffic and otherwise managing
134    /// a DLPI link.
135    pub fn dlpi_open(
136        linkname: *const c_char,
137        dhp: *mut *mut dlpi_handle_t,
138        flags: c_uint,
139    ) -> i32;
140
141    /// Closes the open DLPI link instance associated with the provided handle.
142    pub fn dlpi_close(dh: *mut dlpi_handle_t);
143
144    /// Attempt to send the contets of msgbuf over the DLPI link instance
145    /// associated with the provided DLPI handle.
146    pub fn dlpi_send(
147        dh: *mut dlpi_handle_t,
148        daddrp: *const c_void,
149        daddrlen: usize,
150        msgbuf: *const c_void,
151        msglen: usize,
152        sendp: *const dlpi_sendinfo_t,
153    ) -> i32;
154
155    /// Attempt to receive data messages over the DLIP link instance associated
156    /// with the provided DLPI handle.
157    pub fn dlpi_recv(
158        dh: *mut dlpi_handle_t,
159        saddrp: *mut c_void,
160        saddrlenp: *mut usize,
161        msgbuf: *mut c_void,
162        msglenp: *mut usize,
163        msec: c_int,
164        recvp: *mut dlpi_recvinfo_t,
165    ) -> i32;
166
167    /// Attempt to bind the provided DLPI handle to the service access point
168    /// `sap`.
169    pub fn dlpi_bind(
170        dh: *mut dlpi_handle_t,
171        sap: c_uint,
172        boundsap: *mut c_uint,
173    ) -> i32;
174
175    /// Enable reception of messages destined to the multicast address pointed
176    /// to by addrp.
177    pub fn dlpi_enabmulti(
178        dh: *mut dlpi_handle_t,
179        addrp: *const c_void,
180        addrlen: usize,
181    ) -> i32;
182
183    /// Disable reception of messages destined to the multicast address pointed
184    /// to by addrp.
185    pub fn dlpi_disabmulti(
186        dh: *mut dlpi_handle_t,
187        addrp: *const c_void,
188        addrlen: usize,
189    ) -> i32;
190
191    /// Enable promiscuous mode for the specified handle. See DL_PROMISC_*
192    /// for levels.
193    pub fn dlpi_promiscon(dh: *mut dlpi_handle_t, level: c_uint) -> i32;
194
195    /// Disable promiscuous mode for the specified handle. See DL_PROMISC_*
196    /// for levels.
197    pub fn dlpi_promiscoff(dh: *mut dlpi_handle_t, level: c_uint) -> i32;
198
199    /// Returns a file descriptor that can be used to directly operate on the
200    /// open DLPI stream associated with the provided handle.
201    pub fn dlpi_fd(dh: *mut dlpi_handle_t) -> i32;
202
203}
204
205/// A convenience method for creating a null dlpi handle to be later initialized
206/// by `dlpi_open`.
207pub fn null_dlpi_handle() -> *mut dlpi_handle_t {
208    std::ptr::null_mut::<dlpi_handle_t>()
209}