Debian Codegraph @

libs/gst/helpers/ptp/ffi.rs

raw
1 // GStreamer
2 //
3 // Copyright (C) 2015-2023 Sebastian Dröge <[email protected]>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
6 // If a copy of the MPL was not distributed with this file, You can obtain one at
7 // <https://mozilla.org/MPL/2.0/>.
8 //
9 // SPDX-License-Identifier: MPL-2.0
10
11 #[cfg(unix)]
12 #[allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
13 pub mod unix {
14 use std::os::{raw::*, unix::io::RawFd};
15
16 #[cfg(not(any(
17 target_os = "linux",
18 target_os = "freebsd",
19 target_os = "openbsd",
20 target_os = "netbsd",
21 target_os = "dragonfly",
22 target_os = "macos",
23 target_os = "solaris",
24 target_os = "illumos",
25 target_os = "hurd",
26 )))]
27 compile_error!("Unsupported Operating System");
28
29 // The API definitions below are taken from the libc crate version 0.2.139, the corresponding C
30 // headers, manpages and related documentation.
31 //
32 // XXX: Once meson has cargo subproject support all of the below can be replaced with the libc crate.
33 pub const STDIN_FILENO: RawFd = 0;
34 pub const STDOUT_FILENO: RawFd = 1;
35 #[cfg(not(test))]
36 pub const STDERR_FILENO: RawFd = 2;
37 pub const O_RDONLY: c_int = 0;
38
39 pub const POLLIN: c_short = 0x1;
40 pub const POLLERR: c_short = 0x8;
41 pub const POLLHUP: c_short = 0x10;
42 pub const POLLNVAL: c_short = 0x20;
43
44 pub const IPPROTO_IP: c_int = 0;
45
46 #[cfg(any(
47 target_os = "freebsd",
48 target_os = "openbsd",
49 target_os = "netbsd",
50 target_os = "dragonfly",
51 target_os = "macos",
52 target_os = "hurd",
53 ))]
54 pub const IP_ADD_MEMBERSHIP: c_int = 12;
55 #[cfg(target_os = "linux")]
56 pub const IP_ADD_MEMBERSHIP: c_int = 35;
57 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
58 pub const IP_ADD_MEMBERSHIP: c_int = 19;
59
60 #[cfg(any(
61 target_os = "freebsd",
62 target_os = "openbsd",
63 target_os = "netbsd",
64 target_os = "dragonfly",
65 target_os = "macos",
66 target_os = "hurd",
67 ))]
68 pub const IP_MULTICAST_IF: c_int = 9;
69 #[cfg(target_os = "linux")]
70 pub const IP_MULTICAST_IF: c_int = 32;
71 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
72 pub const IP_MULTICAST_IF: c_int = 16;
73
74 #[cfg(any(
75 target_os = "solaris",
76 target_os = "illumos",
77 target_os = "freebsd",
78 target_os = "openbsd",
79 target_os = "netbsd",
80 target_os = "dragonfly",
81 target_os = "macos",
82 target_os = "hurd",
83 ))]
84 pub const SOL_SOCKET: c_int = 0xffff;
85 #[cfg(all(
86 target_os = "linux",
87 any(
88 target_arch = "sparc",
89 target_arch = "sparc64",
90 target_arch = "mips",
91 target_arch = "mips64",
92 )
93 ))]
94 pub const SOL_SOCKET: c_int = 0xffff;
95 #[cfg(all(
96 target_os = "linux",
97 not(any(
98 target_arch = "sparc",
99 target_arch = "sparc64",
100 target_arch = "mips",
101 target_arch = "mips64",
102 )),
103 ))]
104 pub const SOL_SOCKET: c_int = 1;
105
106 #[cfg(target_os = "linux")]
107 pub const SO_BINDTODEVICE: c_int = 25;
108
109 #[cfg(target_os = "linux")]
110 pub const SO_BINDTOIFINDEX: c_int = 62;
111
112 #[cfg(target_os = "macos")]
113 pub const FIOCLEX: c_ulong = 0x20006601;
114
115 #[cfg(target_os = "macos")]
116 pub const SO_NOSIGPIPE: c_int = 0x1022;
117
118 #[cfg(any(
119 target_os = "solaris",
120 target_os = "illumos",
121 target_os = "freebsd",
122 target_os = "openbsd",
123 target_os = "netbsd",
124 target_os = "dragonfly",
125 target_os = "macos",
126 target_os = "hurd",
127 ))]
128 pub const SO_REUSEADDR: c_int = 0x4;
129 #[cfg(all(
130 target_os = "linux",
131 any(
132 target_arch = "sparc",
133 target_arch = "sparc64",
134 target_arch = "mips",
135 target_arch = "mips64",
136 ),
137 ))]
138 pub const SO_REUSEADDR: c_int = 0x4;
139 #[cfg(all(
140 target_os = "linux",
141 not(any(
142 target_arch = "sparc",
143 target_arch = "sparc64",
144 target_arch = "mips",
145 target_arch = "mips64",
146 )),
147 ))]
148 pub const SO_REUSEADDR: c_int = 2;
149
150 #[cfg(any(
151 target_os = "freebsd",
152 target_os = "openbsd",
153 target_os = "netbsd",
154 target_os = "dragonfly",
155 target_os = "macos",
156 target_os = "hurd",
157 ))]
158 pub const SO_REUSEPORT: c_int = 0x200;
159 #[cfg(all(
160 target_os = "linux",
161 any(
162 target_arch = "sparc",
163 target_arch = "sparc64",
164 target_arch = "mips",
165 target_arch = "mips64",
166 ),
167 ))]
168 pub const SO_REUSEPORT: c_int = 0x200;
169 #[cfg(all(
170 target_os = "linux",
171 not(any(
172 target_arch = "sparc",
173 target_arch = "sparc64",
174 target_arch = "mips",
175 target_arch = "mips64"
176 )),
177 ))]
178 pub const SO_REUSEPORT: c_int = 15;
179
180 #[cfg(any(
181 target_os = "freebsd",
182 target_os = "dragonfly",
183 target_os = "netbsd",
184 target_os = "hurd",
185 ))]
186 pub const SOCK_CLOEXEC: c_int = 0x10000000;
187 #[cfg(target_os = "openbsd")]
188 pub const SOCK_CLOEXEC: c_int = 0x8000;
189 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
190 pub const SOCK_CLOEXEC: c_int = 0x080000;
191 #[cfg(all(
192 target_os = "linux",
193 any(target_arch = "sparc", target_arch = "sparc64"),
194 ))]
195 pub const SOCK_CLOEXEC: c_int = 0x400000;
196 #[cfg(all(
197 target_os = "linux",
198 not(any(target_arch = "sparc", target_arch = "sparc64")),
199 ))]
200 pub const SOCK_CLOEXEC: c_int = 0x80000;
201
202 #[cfg(any(
203 target_os = "freebsd",
204 target_os = "dragonfly",
205 target_os = "netbsd",
206 target_os = "openbsd",
207 target_os = "macos",
208 target_os = "hurd",
209 ))]
210 pub const SOCK_DGRAM: c_int = 2;
211 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
212 pub const SOCK_DGRAM: c_int = 1;
213 #[cfg(all(target_os = "linux", any(target_arch = "mips", target_arch = "mips64"),))]
214 pub const SOCK_DGRAM: c_int = 1;
215 #[cfg(all(
216 target_os = "linux",
217 not(any(target_arch = "mips", target_arch = "mips64")),
218 ))]
219 pub const SOCK_DGRAM: c_int = 2;
220
221 pub const AF_INET: c_int = 2;
222 #[cfg(any(
223 target_os = "freebsd",
224 target_os = "openbsd",
225 target_os = "netbsd",
226 target_os = "dragonfly",
227 target_os = "macos",
228 target_os = "hurd",
229 ))]
230 pub const AF_LINK: c_int = 18;
231 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
232 pub const AF_LINK: c_int = 25;
233 #[cfg(target_os = "linux")]
234 pub const AF_PACKET: c_int = 17;
235
236 #[cfg(any(
237 target_os = "linux",
238 target_os = "freebsd",
239 target_os = "openbsd",
240 target_os = "netbsd",
241 target_os = "dragonfly",
242 target_os = "macos",
243 target_os = "hurd",
244 ))]
245 pub type IfaFlags = c_uint;
246 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
247 pub type IfaFlags = u64;
248
249 pub const IFF_UP: IfaFlags = 0x1;
250 pub const IFF_LOOPBACK: IfaFlags = 0x8;
251
252 #[cfg(any(target_os = "linux", target_os = "hurd"))]
253 pub const IFF_MULTICAST: IfaFlags = 0x1000;
254 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
255 pub const IFF_MULTICAST: IfaFlags = 0x0800;
256 #[cfg(any(
257 target_os = "freebsd",
258 target_os = "openbsd",
259 target_os = "netbsd",
260 target_os = "dragonfly",
261 target_os = "macos",
262 ))]
263 pub const IFF_MULTICAST: IfaFlags = 0x08000;
264
265 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
266 pub const IF_NAMESIZE: usize = 32;
267 #[cfg(not(any(
268 target_os = "linux",
269 target_os = "solaris",
270 target_os = "illumos",
271 target_os = "hurd",
272 )))]
273 pub const IF_NAMESIZE: usize = 16;
274
275 pub const PRIO_PROCESS: c_int = 0;
276
277 extern "C" {
278 #[cfg_attr(
279 all(target_os = "macos", target_arch = "x86"),
280 link_name = "open$UNIX2003"
281 )]
282 pub fn open(path: *const u8, oflag: c_int, ...) -> i32;
283 #[cfg_attr(
284 all(target_os = "macos", target_arch = "x86"),
285 link_name = "read$UNIX2003"
286 )]
287 pub fn read(fd: RawFd, buf: *mut u8, count: usize) -> isize;
288 #[cfg_attr(
289 all(target_os = "macos", target_arch = "x86"),
290 link_name = "write$UNIX2003"
291 )]
292 pub fn write(fd: RawFd, buf: *const u8, count: usize) -> isize;
293
294 #[cfg_attr(
295 all(target_os = "macos", target_arch = "x86"),
296 link_name = "close$UNIX2003"
297 )]
298 pub fn close(fd: c_int) -> c_int;
299
300 #[cfg_attr(
301 all(target_os = "macos", target_arch = "x86"),
302 link_name = "poll$UNIX2003"
303 )]
304 pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int;
305
306 pub fn if_nametoindex(name: *const c_char) -> c_uint;
307 pub fn setsockopt(
308 socket: c_int,
309 level: c_int,
310 name: c_int,
311 value: *const c_void,
312 option_len: u32,
313 ) -> c_int;
314
315 pub fn getifaddrs(ifap: *mut *mut ifaddrs) -> c_int;
316 pub fn freeifaddrs(ifa: *mut ifaddrs);
317
318 pub fn setpriority(which: c_int, who: c_int, prio: c_int) -> c_int;
319
320 #[cfg_attr(target_os = "netbsd", link_name = "__socket30")]
321 #[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")]
322 pub fn socket(domain: c_int, ty: c_int, protocol: c_int) -> c_int;
323
324 #[cfg_attr(target_os = "illumos", link_name = "__xnet_bind")]
325 #[cfg_attr(
326 all(target_os = "macos", target_arch = "x86"),
327 link_name = "bind$UNIX2003"
328 )]
329 pub fn bind(socket: c_int, address: *const sockaddr, address_len: u32) -> c_int;
330
331 #[cfg(target_os = "macos")]
332 pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int;
333
334 #[cfg(test)]
335 pub fn pipe(pipefd: *mut i32) -> i32;
336 }
337
338 #[cfg(any(
339 target_os = "linux",
340 target_os = "solaris",
341 target_os = "illumos",
342 target_os = "hurd",
343 ))]
344 pub type nfds_t = c_ulong;
345 #[cfg(not(any(
346 target_os = "linux",
347 target_os = "solaris",
348 target_os = "illumos",
349 target_os = "hurd",
350 )))]
351 pub type nfds_t = c_uint;
352
353 #[repr(C)]
354 #[derive(Clone, Copy)]
355 pub struct pollfd {
356 pub fd: c_int,
357 pub events: c_short,
358 pub revents: c_short,
359 }
360
361 pub type in_addr_t = u32;
362
363 #[repr(C)]
364 #[derive(Copy, Clone)]
365 pub struct in_addr {
366 pub s_addr: in_addr_t,
367 }
368
369 // Solaris does not have support for this so we fall back to use the std API
370 #[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
371 #[repr(C)]
372 #[derive(Copy, Clone)]
373 pub struct ip_mreqn {
374 pub imr_multiaddr: in_addr,
375 pub imr_address: in_addr,
376 pub imr_ifindex: c_int,
377 }
378
379 // macOS uses ip_mreq instead of ip_mreqn in its latest version of the MAC Kernel for IP_ADD_MEMBERSHIP
380 #[cfg(target_os = "macos")]
381 #[repr(C)]
382 #[derive(Copy, Clone)]
383 pub struct ip_mreq {
384 pub imr_multiaddr: in_addr,
385 pub imr_address: in_addr,
386 }
387
388 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
389 #[repr(C)]
390 pub struct ifaddrs {
391 pub ifa_next: *mut ifaddrs,
392 pub ifa_name: *mut c_char,
393 pub ifa_flags: IfaFlags,
394 pub ifa_addr: *mut sockaddr,
395 pub ifa_netmask: *mut sockaddr,
396 pub ifa_dstaddr: *mut sockaddr,
397 pub ifa_data: *mut c_void,
398 }
399
400 #[cfg(any(target_os = "linux", target_os = "hurd"))]
401 #[repr(C)]
402 pub struct ifaddrs {
403 pub ifa_next: *mut ifaddrs,
404 pub ifa_name: *mut c_char,
405 pub ifa_flags: IfaFlags,
406 pub ifa_addr: *mut sockaddr,
407 pub ifa_netmask: *mut sockaddr,
408 pub ifa_ifu: *mut sockaddr,
409 pub ifa_data: *mut c_void,
410 }
411
412 #[cfg(any(
413 target_os = "freebsd",
414 target_os = "openbsd",
415 target_os = "netbsd",
416 target_os = "dragonfly",
417 target_os = "macos",
418 ))]
419 #[repr(C)]
420 pub struct ifaddrs {
421 pub ifa_next: *mut ifaddrs,
422 pub ifa_name: *mut c_char,
423 pub ifa_flags: IfaFlags,
424 pub ifa_addr: *mut sockaddr,
425 pub ifa_netmask: *mut sockaddr,
426 pub ifa_dstaddr: *mut sockaddr,
427 pub ifa_data: *mut c_void,
428 #[cfg(target_os = "netbsd")]
429 pub ifa_addrflags: c_uint,
430 }
431
432 #[cfg(any(target_os = "linux", target_os = "solaris", target_os = "illumos"))]
433 #[repr(C)]
434 pub struct sockaddr {
435 pub sa_family: u16,
436 pub sa_data: [u8; 14],
437 }
438
439 #[cfg(any(
440 target_os = "freebsd",
441 target_os = "openbsd",
442 target_os = "netbsd",
443 target_os = "dragonfly",
444 target_os = "macos",
445 target_os = "hurd",
446 ))]
447 #[repr(C)]
448 pub struct sockaddr {
449 pub sa_len: u8,
450 pub sa_family: u8,
451 pub sa_data: [u8; 14],
452 }
453
454 #[cfg(any(target_os = "linux", target_os = "solaris", target_os = "illumos"))]
455 #[repr(C)]
456 pub struct sockaddr_in {
457 pub sin_family: u16,
458 pub sin_port: u16,
459 pub sin_addr: in_addr,
460 pub sin_zero: [u8; 8],
461 }
462 #[cfg(any(
463 target_os = "freebsd",
464 target_os = "openbsd",
465 target_os = "netbsd",
466 target_os = "dragonfly",
467 target_os = "macos",
468 target_os = "hurd",
469 ))]
470 #[repr(C)]
471 pub struct sockaddr_in {
472 pub sin_len: u8,
473 pub sin_family: u8,
474 pub sin_port: u16,
475 pub sin_addr: in_addr,
476 pub sin_zero: [u8; 8],
477 }
478
479 #[cfg(any(target_os = "solaris", target_os = "illumos"))]
480 #[repr(C)]
481 pub struct sockaddr_dl {
482 pub sdl_family: u16,
483 pub sdl_index: u16,
484 pub sdl_type: u8,
485 pub sdl_nlen: u8,
486 pub sdl_alen: u8,
487 pub sdl_slen: u8,
488 pub sdl_data: [u8; 244],
489 }
490
491 #[cfg(any(target_os = "netbsd", target_os = "macos"))]
492 #[repr(C)]
493 pub struct sockaddr_dl {
494 pub sdl_len: u8,
495 pub sdl_family: u8,
496 pub sdl_index: u16,
497 pub sdl_type: u8,
498 pub sdl_nlen: u8,
499 pub sdl_alen: u8,
500 pub sdl_slen: u8,
501 pub sdl_data: [u8; 12],
502 }
503
504 #[cfg(target_os = "openbsd")]
505 #[repr(C)]
506 pub struct sockaddr_dl {
507 pub sdl_len: u8,
508 pub sdl_family: u8,
509 pub sdl_index: u16,
510 pub sdl_type: u8,
511 pub sdl_nlen: u8,
512 pub sdl_alen: u8,
513 pub sdl_slen: u8,
514 pub sdl_data: [u8; 24],
515 }
516
517 #[cfg(target_os = "freebsd")]
518 #[repr(C)]
519 pub struct sockaddr_dl {
520 pub sdl_len: u8,
521 pub sdl_family: u8,
522 pub sdl_index: u16,
523 pub sdl_type: u8,
524 pub sdl_nlen: u8,
525 pub sdl_alen: u8,
526 pub sdl_slen: u8,
527 pub sdl_data: [u8; 46],
528 }
529
530 #[cfg(target_os = "dragonfly")]
531 #[repr(C)]
532 pub struct sockaddr_dl {
533 pub sdl_len: u8,
534 pub sdl_family: u8,
535 pub sdl_index: u16,
536 pub sdl_type: u8,
537 pub sdl_nlen: u8,
538 pub sdl_alen: u8,
539 pub sdl_slen: u8,
540 pub sdl_data: [u8; 12],
541 pub sdl_rcf: u16,
542 pub sdl_route: [u8; 16],
543 }
544
545 #[cfg(target_os = "linux")]
546 #[repr(C)]
547 pub struct sockaddr_ll {
548 pub sll_family: u16,
549 pub sll_protocol: u16,
550 pub sll_ifindex: u32,
551 pub sll_hatype: u16,
552 pub sll_pkttype: u8,
553 pub sll_halen: u8,
554 pub sll_addr: [u8; 8],
555 }
556
557 #[cfg(target_os = "linux")]
558 pub mod linux {
559 pub use super::*;
560
561 #[cfg(target_arch = "x86")]
562 pub const SYS_getrandom: c_ulong = 355;
563 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
564 pub const SYS_getrandom: c_ulong = 0x40000000 + 318;
565 #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
566 pub const SYS_getrandom: c_ulong = 318;
567 #[cfg(target_arch = "arm")]
568 pub const SYS_getrandom: c_ulong = 384;
569 #[cfg(target_arch = "aarch64")]
570 pub const SYS_getrandom: c_ulong = 278;
571 #[cfg(target_arch = "mips")]
572 pub const SYS_getrandom: c_ulong = 4000 + 353;
573 #[cfg(target_arch = "mips64")]
574 pub const SYS_getrandom: c_ulong = 5000 + 313;
575 #[cfg(any(
576 target_arch = "riscv32",
577 target_arch = "riscv64",
578 target_arch = "loongarch64"
579 ))]
580 pub const SYS_getrandom: c_ulong = 278;
581 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
582 pub const SYS_getrandom: c_ulong = 359;
583 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
584 pub const SYS_getrandom: c_ulong = 347;
585 #[cfg(target_arch = "s390x")]
586 pub const SYS_getrandom: c_ulong = 349;
587 #[cfg(target_arch = "m68k")]
588 pub const SYS_getrandom: c_ulong = 352;
589 #[cfg(not(any(
590 target_arch = "x86",
591 target_arch = "x86_64",
592 target_arch = "arm",
593 target_arch = "aarch64",
594 target_arch = "mips",
595 target_arch = "mips64",
596 target_arch = "riscv32",
597 target_arch = "riscv64",
598 target_arch = "loongarch64",
599 target_arch = "powerpc",
600 target_arch = "powerpc64",
601 target_arch = "sparc",
602 target_arch = "sparc64",
603 target_arch = "s390x",
604 target_arch = "m68k",
605 )))]
606 pub const SYS_getrandom: c_ulong = 0;
607
608 extern "C" {
609 pub fn syscall(num: c_ulong, ...) -> c_long;
610 }
611 }
612
613 #[cfg(target_os = "macos")]
614 pub mod macos {
615 pub use super::*;
616
617 #[repr(C)]
618 pub struct mach_timebase_info {
619 pub numer: u32,
620 pub denom: u32,
621 }
622
623 extern "C" {
624 pub fn mach_timebase_info(info: *mut mach_timebase_info) -> c_int;
625 pub fn mach_absolute_time() -> u64;
626 }
627 }
628
629 #[cfg(not(target_os = "macos"))]
630 pub mod clock_gettime {
631 pub use super::*;
632
633 #[cfg(any(
634 target_os = "linux",
635 target_os = "freebsd",
636 target_os = "openbsd",
637 target_os = "netbsd",
638 target_os = "solaris",
639 target_os = "illumos",
640 target_os = "hurd",
641 ))]
642 pub type clock_id_t = c_int;
643
644 #[cfg(target_os = "dragonfly")]
645 pub type clock_id_t = c_ulong;
646
647 #[cfg(any(target_os = "solaris", target_os = "illumos", target_os = "hurd"))]
648 pub type time_t = c_long;
649
650 #[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly"))]
651 pub type time_t = i64;
652
653 #[cfg(all(target_os = "freebsd", target_arch = "x86"))]
654 pub type time_t = i32;
655 #[cfg(all(target_os = "freebsd", not(target_arch = "x86")))]
656 pub type time_t = i64;
657
658 #[cfg(all(target_os = "linux", target_env = "gnu", target_arch = "riscv32"))]
659 pub type time_t = i64;
660 #[cfg(all(
661 target_os = "linux",
662 target_env = "gnu",
663 any(
664 target_arch = "x86",
665 target_arch = "arm",
666 target_arch = "m68k",
667 target_arch = "mips",
668 target_arch = "powerpc",
669 target_arch = "sparc",
670 all(target_arch = "aarch64", target_pointer_width = "32"),
671 )
672 ))]
673 pub type time_t = i32;
674 #[cfg(all(
675 target_os = "linux",
676 target_env = "gnu",
677 any(
678 target_arch = "x86_64",
679 all(target_arch = "aarch64", target_pointer_width = "64"),
680 target_arch = "powerpc64",
681 target_arch = "mips64",
682 target_arch = "s390x",
683 target_arch = "sparc64",
684 target_arch = "riscv64",
685 target_arch = "loongarch64",
686 )
687 ))]
688 pub type time_t = i64;
689 #[cfg(all(target_os = "linux", target_env = "musl"))]
690 pub type time_t = c_long;
691
692 #[cfg(all(target_os = "linux", target_env = "uclibc", target_arch = "x86_64"))]
693 pub type time_t = c_int;
694 #[cfg(all(
695 target_os = "linux",
696 target_env = "uclibc",
697 not(target_arch = "x86_64"),
698 ))]
699 pub type time_t = c_long;
700
701 #[repr(C)]
702 pub struct timespec {
703 pub tv_sec: time_t,
704 #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
705 pub tv_nsec: i64,
706 #[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
707 pub tv_nsec: c_long,
708 }
709
710 #[cfg(any(
711 target_os = "freebsd",
712 target_os = "dragonfly",
713 target_os = "solaris",
714 target_os = "illumos",
715 ))]
716 pub const CLOCK_MONOTONIC: clock_id_t = 4;
717
718 #[cfg(any(target_os = "openbsd", target_os = "netbsd",))]
719 pub const CLOCK_MONOTONIC: clock_id_t = 3;
720
721 #[cfg(any(target_os = "linux", target_os = "hurd"))]
722 pub const CLOCK_MONOTONIC: clock_id_t = 1;
723
724 extern "C" {
725 pub fn clock_gettime(clk_id: clock_id_t, tp: *mut timespec) -> c_int;
726 }
727 }
728
729 #[cfg(ptp_helper_permissions = "setcap")]
730 pub mod setcaps {
731 use super::*;
732
733 pub type cap_t = *mut c_void;
734
735 #[link(name = "cap")]
736 extern "C" {
737 pub fn cap_clear(c: cap_t) -> c_int;
738 pub fn cap_get_proc() -> cap_t;
739 pub fn cap_set_proc(c: cap_t) -> c_int;
740 pub fn cap_free(c: cap_t) -> c_int;
741 }
742 }
743
744 #[cfg(ptp_helper_permissions = "setuid-root")]
745 pub mod setuid_root {
746 use super::*;
747
748 pub type uid_t = u32;
749 pub type gid_t = u32;
750
751 #[repr(C)]
752 pub struct passwd {
753 pub pw_name: *mut c_char,
754 pub pw_passwd: *mut c_char,
755 pub pw_uid: uid_t,
756 pub pw_gid: gid_t,
757 // More fields following here
758 truncated: c_void,
759 }
760
761 #[repr(C)]
762 pub struct group {
763 pub gr_name: *mut c_char,
764 pub gr_passwd: *mut c_char,
765 pub gr_gid: gid_t,
766 // More fields following here
767 truncated: c_void,
768 }
769
770 extern "C" {
771 #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam50")]
772 pub fn getpwnam(name: *const c_char) -> *mut passwd;
773 pub fn getgrnam(name: *const c_char) -> *mut group;
774 pub fn setgid(gid: gid_t) -> c_int;
775 pub fn getgid() -> gid_t;
776 pub fn setuid(gid: gid_t) -> c_int;
777 }
778 }
779 }
780
781 #[cfg(windows)]
782 #[allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
783 pub mod windows {
784 use std::os::{
785 raw::*,
786 windows::raw::{HANDLE, SOCKET},
787 };
788
789 // The API definitions below are taken from the windows-sys crate version 0.45.0, the
790 // corresponding C headers, MSDN and related documentation.
791 //
792 // XXX: Once meson has cargo subproject support all of the below can be replaced with the windows-sys crate.
793 pub const INVALID_HANDLE_VALUE: HANDLE = (-1 as isize as usize) as HANDLE;
794 pub const INVALID_SOCKET: SOCKET = (-1 as isize as usize) as SOCKET;
795
796 pub const STD_INPUT_HANDLE: i32 = -10;
797 pub const STD_OUTPUT_HANDLE: i32 = -11;
798 #[cfg(not(test))]
799 pub const STD_ERROR_HANDLE: i32 = -12;
800
801 pub const FILE_TYPE_CHAR: u32 = 0x0002;
802 pub const FILE_TYPE_PIPE: u32 = 0x0003;
803
804 pub const THREAD_PRIORITY_TIME_CRITICAL: i32 = 15;
805
806 #[link(name = "kernel32")]
807 extern "system" {
808 pub fn GetStdHandle(nstdhandle: i32) -> HANDLE;
809
810 pub fn ReadFile(
811 hfile: HANDLE,
812 lpbuffer: *mut u8,
813 nnumberofbytestoread: u32,
814 lpnumberofbytesread: *mut u32,
815 lpoverlapped: *mut c_void,
816 ) -> i32;
817
818 pub fn WriteFile(
819 hfile: HANDLE,
820 lpbuffer: *const u8,
821 nnumberofbytestowrite: u32,
822 lpnumberofbyteswritten: *mut u32,
823 lpoverlapped: *mut c_void,
824 ) -> i32;
825
826 pub fn WaitForMultipleObjects(
827 ncount: u32,
828 lphandles: *const HANDLE,
829 bwaitall: i32,
830 dwmilliseconds: u32,
831 ) -> u32;
832
833 pub fn SetConsoleMode(hconsolehandle: HANDLE, dwmode: u32) -> i32;
834 pub fn FlushConsoleInputBuffer(hconsolehandle: HANDLE) -> i32;
835
836 pub fn CreateEventA(
837 lpeventattributes: *const c_void,
838 bmanualreset: i32,
839 binitialstate: i32,
840 lpname: *const u8,
841 ) -> HANDLE;
842 pub fn SetEvent(hevent: HANDLE) -> i32;
843 pub fn ResetEvent(hevent: HANDLE) -> i32;
844 pub fn CloseHandle(hobject: HANDLE) -> i32;
845
846 pub fn GetFileType(hfile: HANDLE) -> u32;
847
848 pub fn GetProcessHeap() -> isize;
849 pub fn HeapAlloc(hheap: isize, dwflags: u32, dwbytes: usize) -> *mut c_void;
850 pub fn HeapFree(hheap: isize, dwflags: u32, lpmem: *mut c_void) -> i32;
851 pub fn HeapReAlloc(
852 hheap: isize,
853 dwflags: u32,
854 lpmem: *mut c_void,
855 dwbytes: usize,
856 ) -> *mut c_void;
857
858 pub fn SetThreadPriority(pthread: HANDLE, npriority: i32) -> i32;
859 pub fn GetCurrentThread() -> HANDLE;
860
861 #[cfg(test)]
862 pub fn CreatePipe(
863 hreadpipe: *mut HANDLE,
864 hwritepipe: *mut HANDLE,
865 lppipeattributes: *mut c_void,
866 nsize: u32,
867 ) -> i32;
868
869 pub fn QueryPerformanceFrequency(lpfrequence: *mut i64) -> i32;
870 pub fn QueryPerformanceCounter(lpperformancecount: *mut i64) -> i32;
871 }
872
873 pub const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 0x00000002;
874
875 #[link(name = "bcrypt")]
876 extern "system" {
877 pub fn BCryptGenRandom(
878 hAlgorithm: *mut c_void,
879 pBuffer: *mut u8,
880 cbBuffer: u32,
881 dwFlags: u32,
882 ) -> u32;
883 }
884
885 pub const FD_READ: u32 = 1;
886 pub const FD_READ_BIT: usize = 0;
887
888 #[repr(C)]
889 #[derive(Copy, Clone)]
890 pub struct WSANETWORKEVENTS {
891 pub lnetworkevents: u32,
892 pub ierrorcode: [i32; 10],
893 }
894
895 pub const IPPROTO_IP: u32 = 0u32;
896
897 pub const IP_ADD_MEMBERSHIP: u32 = 12u32;
898 pub const IP_MULTICAST_IF: u32 = 9u32;
899
900 pub const SOL_SOCKET: u32 = 65535;
901 pub const SO_REUSEADDR: u32 = 4;
902
903 #[repr(C)]
904 #[derive(Copy, Clone)]
905 pub struct IN_ADDR_0_0 {
906 pub s_b1: u8,
907 pub s_b2: u8,
908 pub s_b3: u8,
909 pub s_b4: u8,
910 }
911
912 #[repr(C)]
913 #[derive(Copy, Clone)]
914 pub struct IN_ADDR_0_1 {
915 pub s_w1: u16,
916 pub s_w2: u16,
917 }
918
919 #[repr(C)]
920 #[derive(Copy, Clone)]
921 pub union IN_ADDR_0 {
922 pub S_un_b: IN_ADDR_0_0,
923 pub S_un_w: IN_ADDR_0_1,
924 pub S_addr: u32,
925 }
926
927 #[repr(C)]
928 #[derive(Copy, Clone)]
929 pub struct IN_ADDR {
930 pub S_un: IN_ADDR_0,
931 }
932
933 #[repr(C)]
934 #[derive(Copy, Clone)]
935 pub struct IP_MREQ {
936 pub imr_multiaddr: IN_ADDR,
937 pub imr_address: IN_ADDR,
938 }
939
940 #[link(name = "ws2_32")]
941 extern "system" {
942 pub fn WSAEventSelect(s: SOCKET, heventobject: HANDLE, lnetworkevents: u32) -> i32;
943 pub fn WSAEnumNetworkEvents(
944 s: SOCKET,
945 heventobject: HANDLE,
946 lpnetworkevents: *mut WSANETWORKEVENTS,
947 ) -> i32;
948 pub fn WSACreateEvent() -> HANDLE;
949 pub fn WSACloseEvent(hevent: HANDLE) -> i32;
950 pub fn WSAGetLastError() -> i32;
951
952 pub fn setsockopt(
953 socket: SOCKET,
954 level: i32,
955 name: i32,
956 value: *const c_void,
957 option_len: i32,
958 ) -> i32;
959
960 pub fn WSASocketW(
961 af: i32,
962 ty: i32,
963 protocol: i32,
964 lpprotocolinfo: *const c_void,
965 g: u32,
966 dwflags: u32,
967 ) -> SOCKET;
968 pub fn bind(s: SOCKET, name: *const SOCKADDR, namelen: i32) -> i32;
969 pub fn closesocket(socket: SOCKET) -> i32;
970 }
971
972 pub const AF_INET: u32 = 2;
973
974 pub const SOCK_DGRAM: u16 = 2u16;
975
976 pub const WSA_FLAG_OVERLAPPED: u32 = 1u32;
977 pub const WSA_FLAG_NO_HANDLE_INHERIT: u32 = 128u32;
978
979 pub const GAA_FLAG_SKIP_ANYCAST: u32 = 0x0002;
980 pub const GAA_FLAG_SKIP_MULTICAST: u32 = 0x0004;
981 pub const GAA_FLAG_SKIP_DNS_SERVER: u32 = 0x0008;
982
983 pub const ADAPTER_FLAG_RECEIVE_ONLY: u32 = 0x08;
984 pub const ADAPTER_FLAG_NO_MULTICAST: u32 = 0x10;
985 pub const ADAPTER_FLAG_IPV4_ENABLED: u32 = 0x80;
986
987 pub const IF_TYPE_SOFTWARE_LOOPBACK: u32 = 24;
988
989 pub const IF_OPER_STATUS_UP: u32 = 1;
990
991 pub const ERROR_NOT_ENOUGH_MEMORY: u32 = 8u32;
992
993 #[repr(C)]
994 #[derive(Copy, Clone)]
995 pub struct IP_ADAPTER_ADDRESSES_LH_0_0 {
996 pub length: u32,
997 pub ifindex: u32,
998 }
999
1000 #[repr(C)]
1001 #[derive(Copy, Clone)]
1002 pub union IP_ADAPTER_ADDRESSES_LH_0 {
1003 pub alignment: u64,
1004 pub anonymous: IP_ADAPTER_ADDRESSES_LH_0_0,
1005 }
1006
1007 #[repr(C)]
1008 #[derive(Copy, Clone)]
1009 pub struct IP_ADAPTER_UNICAST_ADDRESS_LH_0_0 {
1010 pub length: u32,
1011 pub ifindex: u32,
1012 }
1013
1014 #[repr(C)]
1015 #[derive(Copy, Clone)]
1016 pub union IP_ADAPTER_UNICAST_ADDRESS_LH_0 {
1017 pub alignment: u64,
1018 pub anonymous: IP_ADAPTER_UNICAST_ADDRESS_LH_0_0,
1019 }
1020
1021 // XXX: Actually SOCKADDR_IN but we don't care about others
1022 #[repr(C)]
1023 pub struct SOCKADDR {
1024 pub sa_family: u16,
1025 pub sin_port: u16,
1026 pub in_addr: IN_ADDR,
1027 pub sin_zero: [u8; 8],
1028 }
1029
1030 #[repr(C)]
1031 pub struct SOCKET_ADDRESS {
1032 pub lpsocketaddr: *mut SOCKADDR,
1033 pub isocketaddrlength: i32,
1034 }
1035
1036 #[repr(C)]
1037 pub struct IP_ADAPTER_UNICAST_ADDRESS_LH {
1038 pub anonymous: IP_ADAPTER_UNICAST_ADDRESS_LH_0,
1039 pub next: *mut IP_ADAPTER_UNICAST_ADDRESS_LH,
1040 pub address: SOCKET_ADDRESS,
1041 // More fields following here
1042 truncated: c_void,
1043 }
1044
1045 #[repr(C)]
1046 pub struct IP_ADAPTER_ADDRESSES_LH {
1047 pub anonymous: IP_ADAPTER_ADDRESSES_LH_0,
1048 pub next: *mut IP_ADAPTER_ADDRESSES_LH,
1049 pub adaptername: *const u8,
1050 pub firstunicastaddress: *mut IP_ADAPTER_UNICAST_ADDRESS_LH,
1051 pub firstanycastaddress: *mut c_void,
1052 pub firstmulticastaddress: *mut c_void,
1053 pub firstdnsserveraddress: *mut c_void,
1054 pub dnssuffix: *const u16,
1055 pub description: *const u16,
1056 pub friendlyname: *const u16,
1057 pub physicaladdress: [u8; 8],
1058 pub physicaladdresslength: u32,
1059 pub flags: u32,
1060 pub mtu: u32,
1061 pub iftype: u32,
1062 pub operstatus: u32,
1063 // More fields following here
1064 truncated: c_void,
1065 }
1066
1067 #[link(name = "iphlpapi")]
1068 extern "system" {
1069 pub fn GetAdaptersAddresses(
1070 family: u32,
1071 flags: u32,
1072 reserved: *mut c_void,
1073 adapteraddresses: *mut IP_ADAPTER_ADDRESSES_LH,
1074 sizepointer: *mut u32,
1075 ) -> u32;
1076 }
1077 }