1use crate::backend::c;
4use bitflags::bitflags;
5
6pub type RawSocketType = u32;
8
9#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
13#[repr(transparent)]
14pub struct SocketType(pub(crate) RawSocketType);
15
16#[rustfmt::skip]
17impl SocketType {
18 pub const STREAM: Self = Self(c::SOCK_STREAM as _);
20
21 pub const DGRAM: Self = Self(c::SOCK_DGRAM as _);
23
24 #[cfg(not(target_os = "espidf"))]
26 pub const SEQPACKET: Self = Self(c::SOCK_SEQPACKET as _);
27
28 #[cfg(not(target_os = "espidf"))]
30 pub const RAW: Self = Self(c::SOCK_RAW as _);
31
32 #[cfg(not(any(target_os = "espidf", target_os = "haiku")))]
34 pub const RDM: Self = Self(c::SOCK_RDM as _);
35
36 #[inline]
38 pub const fn from_raw(raw: RawSocketType) -> Self {
39 Self(raw)
40 }
41
42 #[inline]
44 pub const fn as_raw(self) -> RawSocketType {
45 self.0
46 }
47}
48
49pub type RawAddressFamily = c::sa_family_t;
51
52#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
59#[repr(transparent)]
60pub struct AddressFamily(pub(crate) RawAddressFamily);
61
62#[rustfmt::skip]
63#[allow(non_upper_case_globals)]
64impl AddressFamily {
65 pub const UNSPEC: Self = Self(c::AF_UNSPEC as _);
67 pub const INET: Self = Self(c::AF_INET as _);
74 pub const INET6: Self = Self(c::AF_INET6 as _);
81 #[cfg(not(any(
88 bsd,
89 solarish,
90 windows,
91 target_os = "aix",
92 target_os = "espidf",
93 target_os = "haiku",
94 target_os = "hurd",
95 target_os = "nto",
96 target_os = "vita",
97 )))]
98 pub const NETLINK: Self = Self(c::AF_NETLINK as _);
99 #[doc(alias = "LOCAL")]
101 pub const UNIX: Self = Self(c::AF_UNIX as _);
102 #[cfg(not(any(
104 bsd,
105 solarish,
106 windows,
107 target_os = "aix",
108 target_os = "espidf",
109 target_os = "haiku",
110 target_os = "hurd",
111 target_os = "nto",
112 target_os = "vita",
113 )))]
114 pub const AX25: Self = Self(c::AF_AX25 as _);
115 #[cfg(not(any(
117 target_os = "aix",
118 target_os = "espidf",
119 target_os = "vita",
120 )))]
121 pub const IPX: Self = Self(c::AF_IPX as _);
122 #[cfg(not(any(target_os = "espidf", target_os = "vita")))]
124 pub const APPLETALK: Self = Self(c::AF_APPLETALK as _);
125 #[cfg(not(any(
127 bsd,
128 solarish,
129 windows,
130 target_os = "aix",
131 target_os = "espidf",
132 target_os = "haiku",
133 target_os = "hurd",
134 target_os = "nto",
135 target_os = "vita",
136 )))]
137 pub const NETROM: Self = Self(c::AF_NETROM as _);
138 #[cfg(not(any(
140 bsd,
141 solarish,
142 windows,
143 target_os = "aix",
144 target_os = "espidf",
145 target_os = "haiku",
146 target_os = "hurd",
147 target_os = "nto",
148 target_os = "vita",
149 )))]
150 pub const BRIDGE: Self = Self(c::AF_BRIDGE as _);
151 #[cfg(not(any(
153 bsd,
154 solarish,
155 windows,
156 target_os = "aix",
157 target_os = "espidf",
158 target_os = "haiku",
159 target_os = "hurd",
160 target_os = "nto",
161 target_os = "vita",
162 )))]
163 pub const ATMPVC: Self = Self(c::AF_ATMPVC as _);
164 #[cfg(not(any(
166 bsd,
167 windows,
168 target_os = "aix",
169 target_os = "espidf",
170 target_os = "haiku",
171 target_os = "hurd",
172 target_os = "nto",
173 target_os = "vita",
174 )))]
175 pub const X25: Self = Self(c::AF_X25 as _);
176 #[cfg(not(any(
178 bsd,
179 solarish,
180 windows,
181 target_os = "aix",
182 target_os = "espidf",
183 target_os = "haiku",
184 target_os = "hurd",
185 target_os = "nto",
186 target_os = "vita",
187 )))]
188 pub const ROSE: Self = Self(c::AF_ROSE as _);
189 #[cfg(not(any(target_os = "espidf", target_os = "haiku", target_os = "vita")))]
191 pub const DECnet: Self = Self(c::AF_DECnet as _);
192 #[cfg(not(any(
194 bsd,
195 solarish,
196 windows,
197 target_os = "aix",
198 target_os = "espidf",
199 target_os = "haiku",
200 target_os = "hurd",
201 target_os = "nto",
202 target_os = "vita",
203 )))]
204 pub const NETBEUI: Self = Self(c::AF_NETBEUI as _);
205 #[cfg(not(any(
207 bsd,
208 solarish,
209 windows,
210 target_os = "aix",
211 target_os = "espidf",
212 target_os = "haiku",
213 target_os = "hurd",
214 target_os = "nto",
215 target_os = "vita",
216 )))]
217 pub const SECURITY: Self = Self(c::AF_SECURITY as _);
218 #[cfg(not(any(
220 bsd,
221 windows,
222 target_os = "aix",
223 target_os = "espidf",
224 target_os = "haiku",
225 target_os = "hurd",
226 target_os = "nto",
227 target_os = "vita",
228 )))]
229 pub const KEY: Self = Self(c::AF_KEY as _);
230 #[cfg(not(any(
237 bsd,
238 windows,
239 target_os = "aix",
240 target_os = "espidf",
241 target_os = "haiku",
242 target_os = "hurd",
243 target_os = "nto",
244 target_os = "vita",
245 )))]
246 pub const PACKET: Self = Self(c::AF_PACKET as _);
247 #[cfg(not(any(
249 bsd,
250 solarish,
251 windows,
252 target_os = "aix",
253 target_os = "espidf",
254 target_os = "haiku",
255 target_os = "hurd",
256 target_os = "nto",
257 target_os = "vita",
258 )))]
259 pub const ASH: Self = Self(c::AF_ASH as _);
260 #[cfg(not(any(
262 bsd,
263 solarish,
264 windows,
265 target_os = "aix",
266 target_os = "espidf",
267 target_os = "haiku",
268 target_os = "hurd",
269 target_os = "nto",
270 target_os = "vita",
271 )))]
272 pub const ECONET: Self = Self(c::AF_ECONET as _);
273 #[cfg(not(any(
275 bsd,
276 solarish,
277 windows,
278 target_os = "aix",
279 target_os = "espidf",
280 target_os = "haiku",
281 target_os = "hurd",
282 target_os = "nto",
283 target_os = "vita",
284 )))]
285 pub const ATMSVC: Self = Self(c::AF_ATMSVC as _);
286 #[cfg(not(any(
288 bsd,
289 solarish,
290 windows,
291 target_os = "aix",
292 target_os = "espidf",
293 target_os = "haiku",
294 target_os = "hurd",
295 target_os = "nto",
296 target_os = "vita",
297 )))]
298 pub const RDS: Self = Self(c::AF_RDS as _);
299 #[cfg(not(any(target_os = "espidf", target_os = "haiku", target_os = "vita")))]
301 pub const SNA: Self = Self(c::AF_SNA as _);
302 #[cfg(not(any(
304 bsd,
305 solarish,
306 target_os = "aix",
307 target_os = "espidf",
308 target_os = "haiku",
309 target_os = "hurd",
310 target_os = "nto",
311 target_os = "vita",
312 )))]
313 pub const IRDA: Self = Self(c::AF_IRDA as _);
314 #[cfg(not(any(
316 bsd,
317 solarish,
318 windows,
319 target_os = "aix",
320 target_os = "espidf",
321 target_os = "haiku",
322 target_os = "hurd",
323 target_os = "nto",
324 target_os = "vita",
325 )))]
326 pub const PPPOX: Self = Self(c::AF_PPPOX as _);
327 #[cfg(not(any(
329 bsd,
330 solarish,
331 windows,
332 target_os = "aix",
333 target_os = "espidf",
334 target_os = "haiku",
335 target_os = "hurd",
336 target_os = "nto",
337 target_os = "vita",
338 )))]
339 pub const WANPIPE: Self = Self(c::AF_WANPIPE as _);
340 #[cfg(not(any(
342 bsd,
343 solarish,
344 windows,
345 target_os = "aix",
346 target_os = "espidf",
347 target_os = "haiku",
348 target_os = "hurd",
349 target_os = "nto",
350 target_os = "vita",
351 )))]
352 pub const LLC: Self = Self(c::AF_LLC as _);
353 #[cfg(not(any(
355 bsd,
356 solarish,
357 windows,
358 target_os = "aix",
359 target_os = "espidf",
360 target_os = "haiku",
361 target_os = "hurd",
362 target_os = "nto",
363 target_os = "vita",
364 )))]
365 pub const CAN: Self = Self(c::AF_CAN as _);
366 #[cfg(not(any(
368 bsd,
369 solarish,
370 windows,
371 target_os = "aix",
372 target_os = "espidf",
373 target_os = "haiku",
374 target_os = "hurd",
375 target_os = "nto",
376 target_os = "vita",
377 )))]
378 pub const TIPC: Self = Self(c::AF_TIPC as _);
379 #[cfg(not(any(
381 apple,
382 solarish,
383 windows,
384 target_os = "aix",
385 target_os = "espidf",
386 target_os = "hurd",
387 target_os = "vita",
388 )))]
389 pub const BLUETOOTH: Self = Self(c::AF_BLUETOOTH as _);
390 #[cfg(not(any(
392 bsd,
393 solarish,
394 windows,
395 target_os = "aix",
396 target_os = "espidf",
397 target_os = "haiku",
398 target_os = "hurd",
399 target_os = "nto",
400 target_os = "vita",
401 )))]
402 pub const IUCV: Self = Self(c::AF_IUCV as _);
403 #[cfg(not(any(
405 bsd,
406 solarish,
407 windows,
408 target_os = "aix",
409 target_os = "espidf",
410 target_os = "haiku",
411 target_os = "hurd",
412 target_os = "nto",
413 target_os = "vita",
414 )))]
415 pub const RXRPC: Self = Self(c::AF_RXRPC as _);
416 #[cfg(not(any(
418 solarish,
419 windows,
420 target_os = "aix",
421 target_os = "espidf",
422 target_os = "haiku",
423 target_os = "hurd",
424 target_os = "vita",
425 )))]
426 pub const ISDN: Self = Self(c::AF_ISDN as _);
427 #[cfg(not(any(
429 bsd,
430 solarish,
431 windows,
432 target_os = "aix",
433 target_os = "espidf",
434 target_os = "haiku",
435 target_os = "hurd",
436 target_os = "nto",
437 target_os = "vita",
438 )))]
439 pub const PHONET: Self = Self(c::AF_PHONET as _);
440 #[cfg(not(any(
442 bsd,
443 solarish,
444 windows,
445 target_os = "aix",
446 target_os = "espidf",
447 target_os = "haiku",
448 target_os = "hurd",
449 target_os = "nto",
450 target_os = "vita",
451 )))]
452 pub const IEEE802154: Self = Self(c::AF_IEEE802154 as _);
453 #[cfg(solarish)]
455 pub const EIGHT_ZERO_TWO: Self = Self(c::AF_802 as _);
456 #[cfg(target_os = "fuchsia")]
457 pub const ALG: Self = Self(c::AF_ALG as _);
459 #[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "nto"))]
460 pub const ARP: Self = Self(c::AF_ARP as _);
462 #[cfg(freebsdlike)]
464 pub const ATM: Self = Self(c::AF_ATM as _);
465 #[cfg(any(target_os = "android", target_os = "emscripten", target_os = "fuchsia"))]
467 pub const CAIF: Self = Self(c::AF_CAIF as _);
468 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
470 pub const CCITT: Self = Self(c::AF_CCITT as _);
471 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
473 pub const CHAOS: Self = Self(c::AF_CHAOS as _);
474 #[cfg(any(bsd, target_os = "nto"))]
476 pub const CNT: Self = Self(c::AF_CNT as _);
477 #[cfg(any(bsd, target_os = "nto"))]
479 pub const COIP: Self = Self(c::AF_COIP as _);
480 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
482 pub const DATAKIT: Self = Self(c::AF_DATAKIT as _);
483 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "haiku", target_os = "nto"))]
485 pub const DLI: Self = Self(c::AF_DLI as _);
486 #[cfg(any(bsd, target_os = "nto"))]
488 pub const E164: Self = Self(c::AF_E164 as _);
489 #[cfg(any(apple, freebsdlike, solarish, target_os = "aix", target_os = "nto", target_os = "openbsd"))]
491 pub const ECMA: Self = Self(c::AF_ECMA as _);
492 #[cfg(target_os = "openbsd")]
494 pub const ENCAP: Self = Self(c::AF_ENCAP as _);
495 #[cfg(solarish)]
497 pub const FILE: Self = Self(c::AF_FILE as _);
498 #[cfg(solarish)]
500 pub const GOSIP: Self = Self(c::AF_GOSIP as _);
501 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
503 pub const HYLINK: Self = Self(c::AF_HYLINK as _);
504 #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
506 pub const IB: Self = Self(c::AF_IB as _);
507 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
509 pub const IMPLINK: Self = Self(c::AF_IMPLINK as _);
510 #[cfg(any(apple, freebsdlike, target_os = "netbsd"))]
512 pub const IEEE80211: Self = Self(c::AF_IEEE80211 as _);
513 #[cfg(target_os = "freebsd")]
515 pub const INET6_SDP: Self = Self(c::AF_INET6_SDP as _);
516 #[cfg(solarish)]
518 pub const INET_OFFLOAD: Self = Self(c::AF_INET_OFFLOAD as _);
519 #[cfg(target_os = "freebsd")]
521 pub const INET_SDP: Self = Self(c::AF_INET_SDP as _);
522 #[cfg(target_os = "aix")]
524 pub const INTF: Self = Self(c::AF_INTF as _);
525 #[cfg(any(bsd, target_os = "aix", target_os = "nto"))]
527 pub const ISO: Self = Self(c::AF_ISO as _);
528 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
530 pub const LAT: Self = Self(c::AF_LAT as _);
531 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "haiku", target_os = "nto"))]
533 pub const LINK: Self = Self(c::AF_LINK as _);
534 #[cfg(any(netbsdlike, target_os = "dragonfly", target_os = "emscripten", target_os = "fuchsia"))]
536 pub const MPLS: Self = Self(c::AF_MPLS as _);
537 #[cfg(any(bsd, target_os = "nto"))]
539 pub const NATM: Self = Self(c::AF_NATM as _);
540 #[cfg(solarish)]
542 pub const NBS: Self = Self(c::AF_NBS as _);
543 #[cfg(target_os = "illumos")]
545 pub const NCA: Self = Self(c::AF_NCA as _);
546 #[cfg(target_os = "aix")]
548 pub const NDD: Self = Self(c::AF_NDD as _);
549 #[cfg(apple)]
551 pub const NDRV: Self = Self(c::AF_NDRV as _);
552 #[cfg(any(apple, freebsdlike))]
554 pub const NETBIOS: Self = Self(c::AF_NETBIOS as _);
555 #[cfg(freebsdlike)]
557 pub const NETGRAPH: Self = Self(c::AF_NETGRAPH as _);
558 #[cfg(solarish)]
560 pub const NIT: Self = Self(c::AF_NIT as _);
561 #[cfg(target_os = "haiku")]
563 pub const NOTIFY: Self = Self(c::AF_NOTIFY as _);
564 #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))]
566 pub const NFC: Self = Self(c::AF_NFC as _);
567 #[cfg(any(apple, solarish, netbsdlike, target_os = "aix", target_os = "nto"))]
569 pub const NS: Self = Self(c::AF_NS as _);
570 #[cfg(target_os = "netbsd")]
572 pub const OROUTE: Self = Self(c::AF_OROUTE as _);
573 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
575 pub const OSI: Self = Self(c::AF_OSI as _);
576 #[cfg(solarish)]
578 pub const OSINET: Self = Self(c::AF_OSINET as _);
579 #[cfg(solarish)]
581 pub const POLICY: Self = Self(c::AF_POLICY as _);
582 #[cfg(apple)]
584 pub const PPP: Self = Self(c::AF_PPP as _);
585 #[cfg(any(bsd, solarish, target_os = "aix", target_os = "nto"))]
587 pub const PUP: Self = Self(c::AF_PUP as _);
588 #[cfg(target_os = "aix")]
590 pub const RIF: Self = Self(c::AF_RIF as _);
591 #[cfg(any(bsd, solarish, target_os = "android", target_os = "emscripten", target_os = "fuchsia", target_os = "haiku", target_os = "nto"))]
593 pub const ROUTE: Self = Self(c::AF_ROUTE as _);
594 #[cfg(target_os = "freebsd")]
596 pub const SCLUSTER: Self = Self(c::AF_SCLUSTER as _);
597 #[cfg(any(apple, target_os = "freebsd", target_os = "openbsd"))]
599 pub const SIP: Self = Self(c::AF_SIP as _);
600 #[cfg(target_os = "freebsd")]
602 pub const SLOW: Self = Self(c::AF_SLOW as _);
603 #[cfg(apple)]
605 pub const SYS_CONTROL: Self = Self(c::AF_SYS_CONTROL as _);
606 #[cfg(apple)]
608 pub const SYSTEM: Self = Self(c::AF_SYSTEM as _);
609 #[cfg(solarish)]
611 pub const TRILL: Self = Self(c::AF_TRILL as _);
612 #[cfg(apple)]
614 pub const UTUN: Self = Self(c::AF_UTUN as _);
615 #[cfg(any(apple, target_os = "emscripten", target_os = "fuchsia"))]
617 pub const VSOCK: Self = Self(c::AF_VSOCK as _);
618 #[cfg(target_os = "linux")]
620 pub const XDP: Self = Self(c::AF_XDP as _);
621
622 #[inline]
624 pub const fn from_raw(raw: RawAddressFamily) -> Self {
625 Self(raw)
626 }
627
628 #[inline]
630 pub const fn as_raw(self) -> RawAddressFamily {
631 self.0
632 }
633}
634
635pub type RawProtocol = core::num::NonZeroU32;
637
638const fn new_raw_protocol(u: u32) -> RawProtocol {
639 match RawProtocol::new(u) {
640 Some(p) => p,
641 None => panic!("new_raw_protocol: protocol must be non-zero"),
642 }
643}
644
645#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
658#[repr(transparent)]
659#[doc(alias = "IPPROTO_IP")]
660#[doc(alias = "NETLINK_ROUTE")]
661pub struct Protocol(pub(crate) RawProtocol);
662
663pub mod ipproto {
667 use super::{new_raw_protocol, Protocol};
668 use crate::backend::c;
669
670 pub const ICMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ICMP as _));
672 #[cfg(not(any(
674 solarish,
675 target_os = "espidf",
676 target_os = "haiku",
677 target_os = "vita"
678 )))]
679 pub const IGMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IGMP as _));
680 #[cfg(not(any(
682 solarish,
683 windows,
684 target_os = "espidf",
685 target_os = "haiku",
686 target_os = "vita"
687 )))]
688 pub const IPIP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IPIP as _));
689 pub const TCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_TCP as _));
691 #[cfg(not(any(
693 solarish,
694 target_os = "espidf",
695 target_os = "haiku",
696 target_os = "vita"
697 )))]
698 pub const EGP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_EGP as _));
699 #[cfg(not(any(
701 solarish,
702 target_os = "espidf",
703 target_os = "haiku",
704 target_os = "vita"
705 )))]
706 pub const PUP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_PUP as _));
707 pub const UDP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_UDP as _));
709 #[cfg(not(any(
711 solarish,
712 target_os = "espidf",
713 target_os = "haiku",
714 target_os = "vita"
715 )))]
716 pub const IDP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IDP as _));
717 #[cfg(not(any(
719 solarish,
720 windows,
721 target_os = "espidf",
722 target_os = "haiku",
723 target_os = "vita"
724 )))]
725 pub const TP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_TP as _));
726 #[cfg(not(any(
728 apple,
729 solarish,
730 windows,
731 target_os = "aix",
732 target_os = "dragonfly",
733 target_os = "espidf",
734 target_os = "haiku",
735 target_os = "nto",
736 target_os = "openbsd",
737 target_os = "vita",
738 )))]
739 pub const DCCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_DCCP as _));
740 pub const IPV6: Protocol = Protocol(new_raw_protocol(c::IPPROTO_IPV6 as _));
742 #[cfg(not(any(
744 solarish,
745 windows,
746 target_os = "espidf",
747 target_os = "haiku",
748 target_os = "vita"
749 )))]
750 pub const RSVP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_RSVP as _));
751 #[cfg(not(any(
753 solarish,
754 windows,
755 target_os = "espidf",
756 target_os = "haiku",
757 target_os = "vita"
758 )))]
759 pub const GRE: Protocol = Protocol(new_raw_protocol(c::IPPROTO_GRE as _));
760 #[cfg(not(any(
762 solarish,
763 target_os = "espidf",
764 target_os = "haiku",
765 target_os = "vita"
766 )))]
767 pub const ESP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ESP as _));
768 #[cfg(not(any(
770 solarish,
771 target_os = "espidf",
772 target_os = "haiku",
773 target_os = "vita"
774 )))]
775 pub const AH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_AH as _));
776 #[cfg(not(any(
778 solarish,
779 netbsdlike,
780 windows,
781 target_os = "aix",
782 target_os = "espidf",
783 target_os = "haiku",
784 target_os = "nto",
785 target_os = "vita",
786 )))]
787 pub const MTP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MTP as _));
788 #[cfg(not(any(
790 bsd,
791 solarish,
792 windows,
793 target_os = "aix",
794 target_os = "espidf",
795 target_os = "haiku",
796 target_os = "nto",
797 target_os = "vita",
798 )))]
799 pub const BEETPH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_BEETPH as _));
800 #[cfg(not(any(
802 solarish,
803 windows,
804 target_os = "aix",
805 target_os = "espidf",
806 target_os = "haiku",
807 target_os = "vita",
808 )))]
809 pub const ENCAP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ENCAP as _));
810 #[cfg(not(any(
812 solarish,
813 target_os = "aix",
814 target_os = "espidf",
815 target_os = "haiku",
816 target_os = "vita"
817 )))]
818 pub const PIM: Protocol = Protocol(new_raw_protocol(c::IPPROTO_PIM as _));
819 #[cfg(not(any(
821 bsd,
822 solarish,
823 windows,
824 target_os = "aix",
825 target_os = "espidf",
826 target_os = "haiku",
827 target_os = "nto",
828 target_os = "vita",
829 )))]
830 pub const COMP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_COMP as _));
831 #[cfg(not(any(
833 solarish,
834 target_os = "dragonfly",
835 target_os = "espidf",
836 target_os = "haiku",
837 target_os = "openbsd",
838 target_os = "vita",
839 )))]
840 pub const SCTP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_SCTP as _));
841 #[cfg(not(any(
843 apple,
844 netbsdlike,
845 solarish,
846 windows,
847 target_os = "aix",
848 target_os = "dragonfly",
849 target_os = "espidf",
850 target_os = "haiku",
851 target_os = "nto",
852 target_os = "vita",
853 )))]
854 pub const UDPLITE: Protocol = Protocol(new_raw_protocol(c::IPPROTO_UDPLITE as _));
855 #[cfg(not(any(
857 apple,
858 solarish,
859 windows,
860 target_os = "aix",
861 target_os = "dragonfly",
862 target_os = "espidf",
863 target_os = "haiku",
864 target_os = "netbsd",
865 target_os = "nto",
866 target_os = "vita",
867 )))]
868 pub const MPLS: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MPLS as _));
869 #[cfg(linux_kernel)]
871 pub const ETHERNET: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ETHERNET as _));
872 #[cfg(not(any(target_os = "espidf", target_os = "vita")))]
874 pub const RAW: Protocol = Protocol(new_raw_protocol(c::IPPROTO_RAW as _));
875 #[cfg(not(any(
877 bsd,
878 solarish,
879 windows,
880 target_os = "aix",
881 target_os = "emscripten",
882 target_os = "espidf",
883 target_os = "fuchsia",
884 target_os = "haiku",
885 target_os = "nto",
886 target_os = "vita",
887 )))]
888 pub const MPTCP: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MPTCP as _));
889 #[cfg(not(any(
891 solarish,
892 target_os = "espidf",
893 target_os = "haiku",
894 target_os = "vita"
895 )))]
896 pub const FRAGMENT: Protocol = Protocol(new_raw_protocol(c::IPPROTO_FRAGMENT as _));
897 pub const ICMPV6: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ICMPV6 as _));
899 #[cfg(not(any(
901 apple,
902 netbsdlike,
903 solarish,
904 windows,
905 target_os = "dragonfly",
906 target_os = "espidf",
907 target_os = "haiku",
908 target_os = "nto",
909 target_os = "vita",
910 )))]
911 pub const MH: Protocol = Protocol(new_raw_protocol(c::IPPROTO_MH as _));
912 #[cfg(not(any(
914 solarish,
915 target_os = "espidf",
916 target_os = "haiku",
917 target_os = "vita"
918 )))]
919 pub const ROUTING: Protocol = Protocol(new_raw_protocol(c::IPPROTO_ROUTING as _));
920}
921
922pub mod sysproto {
924 #[cfg(apple)]
925 use {
926 super::{new_raw_protocol, Protocol},
927 crate::backend::c,
928 };
929
930 #[cfg(apple)]
932 pub const EVENT: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_EVENT as _));
933
934 #[cfg(apple)]
936 pub const CONTROL: Protocol = Protocol(new_raw_protocol(c::SYSPROTO_CONTROL as _));
937}
938
939pub mod netlink {
943 #[cfg(linux_kernel)]
944 use {
945 super::{new_raw_protocol, Protocol},
946 crate::backend::c,
947 };
948
949 #[cfg(linux_kernel)]
951 pub const UNUSED: Protocol = Protocol(new_raw_protocol(c::NETLINK_UNUSED as _));
952 #[cfg(linux_kernel)]
954 pub const USERSOCK: Protocol = Protocol(new_raw_protocol(c::NETLINK_USERSOCK as _));
955 #[cfg(linux_kernel)]
957 pub const FIREWALL: Protocol = Protocol(new_raw_protocol(c::NETLINK_FIREWALL as _));
958 #[cfg(linux_kernel)]
960 pub const SOCK_DIAG: Protocol = Protocol(new_raw_protocol(c::NETLINK_SOCK_DIAG as _));
961 #[cfg(linux_kernel)]
963 pub const NFLOG: Protocol = Protocol(new_raw_protocol(c::NETLINK_NFLOG as _));
964 #[cfg(linux_kernel)]
966 pub const XFRM: Protocol = Protocol(new_raw_protocol(c::NETLINK_XFRM as _));
967 #[cfg(linux_kernel)]
969 pub const SELINUX: Protocol = Protocol(new_raw_protocol(c::NETLINK_SELINUX as _));
970 #[cfg(linux_kernel)]
972 pub const ISCSI: Protocol = Protocol(new_raw_protocol(c::NETLINK_ISCSI as _));
973 #[cfg(linux_kernel)]
975 pub const AUDIT: Protocol = Protocol(new_raw_protocol(c::NETLINK_AUDIT as _));
976 #[cfg(linux_kernel)]
978 pub const FIB_LOOKUP: Protocol = Protocol(new_raw_protocol(c::NETLINK_FIB_LOOKUP as _));
979 #[cfg(linux_kernel)]
981 pub const CONNECTOR: Protocol = Protocol(new_raw_protocol(c::NETLINK_CONNECTOR as _));
982 #[cfg(linux_kernel)]
984 pub const NETFILTER: Protocol = Protocol(new_raw_protocol(c::NETLINK_NETFILTER as _));
985 #[cfg(linux_kernel)]
987 pub const IP6_FW: Protocol = Protocol(new_raw_protocol(c::NETLINK_IP6_FW as _));
988 #[cfg(linux_kernel)]
990 pub const DNRTMSG: Protocol = Protocol(new_raw_protocol(c::NETLINK_DNRTMSG as _));
991 #[cfg(linux_kernel)]
993 pub const KOBJECT_UEVENT: Protocol = Protocol(new_raw_protocol(c::NETLINK_KOBJECT_UEVENT as _));
994 #[cfg(linux_kernel)]
1000 pub const GENERIC: Protocol = Protocol(new_raw_protocol(c::NETLINK_GENERIC as _));
1001 #[cfg(linux_kernel)]
1003 pub const SCSITRANSPORT: Protocol = Protocol(new_raw_protocol(c::NETLINK_SCSITRANSPORT as _));
1004 #[cfg(linux_kernel)]
1006 pub const ECRYPTFS: Protocol = Protocol(new_raw_protocol(c::NETLINK_ECRYPTFS as _));
1007 #[cfg(linux_kernel)]
1009 pub const RDMA: Protocol = Protocol(new_raw_protocol(c::NETLINK_RDMA as _));
1010 #[cfg(linux_kernel)]
1012 pub const CRYPTO: Protocol = Protocol(new_raw_protocol(c::NETLINK_CRYPTO as _));
1013 #[cfg(linux_kernel)]
1015 pub const INET_DIAG: Protocol = Protocol(new_raw_protocol(c::NETLINK_INET_DIAG as _));
1016 #[cfg(linux_kernel)]
1018 pub const ADD_MEMBERSHIP: Protocol = Protocol(new_raw_protocol(c::NETLINK_ADD_MEMBERSHIP as _));
1019 #[cfg(linux_kernel)]
1021 pub const DROP_MEMBERSHIP: Protocol =
1022 Protocol(new_raw_protocol(c::NETLINK_DROP_MEMBERSHIP as _));
1023 #[cfg(linux_kernel)]
1025 pub const PKTINFO: Protocol = Protocol(new_raw_protocol(c::NETLINK_PKTINFO as _));
1026 #[cfg(linux_kernel)]
1028 pub const BROADCAST_ERROR: Protocol =
1029 Protocol(new_raw_protocol(c::NETLINK_BROADCAST_ERROR as _));
1030 #[cfg(linux_kernel)]
1032 pub const NO_ENOBUFS: Protocol = Protocol(new_raw_protocol(c::NETLINK_NO_ENOBUFS as _));
1033 #[cfg(linux_kernel)]
1035 pub const RX_RING: Protocol = Protocol(new_raw_protocol(c::NETLINK_RX_RING as _));
1036 #[cfg(linux_kernel)]
1038 pub const TX_RING: Protocol = Protocol(new_raw_protocol(c::NETLINK_TX_RING as _));
1039 #[cfg(linux_kernel)]
1041 pub const LISTEN_ALL_NSID: Protocol =
1042 Protocol(new_raw_protocol(c::NETLINK_LISTEN_ALL_NSID as _));
1043 #[cfg(linux_kernel)]
1045 pub const LIST_MEMBERSHIPS: Protocol =
1046 Protocol(new_raw_protocol(c::NETLINK_LIST_MEMBERSHIPS as _));
1047 #[cfg(linux_kernel)]
1049 pub const CAP_ACK: Protocol = Protocol(new_raw_protocol(c::NETLINK_CAP_ACK as _));
1050 #[cfg(linux_kernel)]
1052 pub const EXT_ACK: Protocol = Protocol(new_raw_protocol(c::NETLINK_EXT_ACK as _));
1053 #[cfg(linux_kernel)]
1055 pub const GET_STRICT_CHK: Protocol = Protocol(new_raw_protocol(c::NETLINK_GET_STRICT_CHK as _));
1056}
1057
1058pub mod eth {
1064 #[cfg(linux_kernel)]
1065 use {
1066 super::{new_raw_protocol, Protocol},
1067 crate::backend::c,
1068 };
1069
1070 #[cfg(linux_kernel)]
1072 pub const LOOP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LOOP as u16).to_be() as u32));
1073 #[cfg(linux_kernel)]
1075 pub const PUP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUP as u16).to_be() as u32));
1076 #[cfg(linux_kernel)]
1078 pub const PUPAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_PUPAT as u16).to_be() as u32));
1079 #[cfg(linux_kernel)]
1081 pub const TSN: Protocol = Protocol(new_raw_protocol((c::ETH_P_TSN as u16).to_be() as u32));
1082 #[cfg(linux_kernel)]
1084 pub const ERSPAN2: Protocol =
1085 Protocol(new_raw_protocol((c::ETH_P_ERSPAN2 as u16).to_be() as u32));
1086 #[cfg(linux_kernel)]
1088 pub const IP: Protocol = Protocol(new_raw_protocol((c::ETH_P_IP as u16).to_be() as u32));
1089 #[cfg(linux_kernel)]
1091 pub const X25: Protocol = Protocol(new_raw_protocol((c::ETH_P_X25 as u16).to_be() as u32));
1092 #[cfg(linux_kernel)]
1094 pub const ARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_ARP as u16).to_be() as u32));
1095 #[cfg(linux_kernel)]
1097 pub const BPQ: Protocol = Protocol(new_raw_protocol((c::ETH_P_BPQ as u16).to_be() as u32));
1098 #[cfg(linux_kernel)]
1100 pub const IEEEPUP: Protocol =
1101 Protocol(new_raw_protocol((c::ETH_P_IEEEPUP as u16).to_be() as u32));
1102 #[cfg(linux_kernel)]
1104 pub const IEEEPUPAT: Protocol =
1105 Protocol(new_raw_protocol((c::ETH_P_IEEEPUPAT as u16).to_be() as u32));
1106 #[cfg(linux_kernel)]
1108 pub const BATMAN: Protocol =
1109 Protocol(new_raw_protocol((c::ETH_P_BATMAN as u16).to_be() as u32));
1110 #[cfg(linux_kernel)]
1112 pub const DEC: Protocol = Protocol(new_raw_protocol((c::ETH_P_DEC as u16).to_be() as u32));
1113 #[cfg(linux_kernel)]
1115 pub const DNA_DL: Protocol =
1116 Protocol(new_raw_protocol((c::ETH_P_DNA_DL as u16).to_be() as u32));
1117 #[cfg(linux_kernel)]
1119 pub const DNA_RC: Protocol =
1120 Protocol(new_raw_protocol((c::ETH_P_DNA_RC as u16).to_be() as u32));
1121 #[cfg(linux_kernel)]
1123 pub const DNA_RT: Protocol =
1124 Protocol(new_raw_protocol((c::ETH_P_DNA_RT as u16).to_be() as u32));
1125 #[cfg(linux_kernel)]
1127 pub const LAT: Protocol = Protocol(new_raw_protocol((c::ETH_P_LAT as u16).to_be() as u32));
1128 #[cfg(linux_kernel)]
1130 pub const DIAG: Protocol = Protocol(new_raw_protocol((c::ETH_P_DIAG as u16).to_be() as u32));
1131 #[cfg(linux_kernel)]
1133 pub const CUST: Protocol = Protocol(new_raw_protocol((c::ETH_P_CUST as u16).to_be() as u32));
1134 #[cfg(linux_kernel)]
1136 pub const SCA: Protocol = Protocol(new_raw_protocol((c::ETH_P_SCA as u16).to_be() as u32));
1137 #[cfg(linux_kernel)]
1139 pub const TEB: Protocol = Protocol(new_raw_protocol((c::ETH_P_TEB as u16).to_be() as u32));
1140 #[cfg(linux_kernel)]
1142 pub const RARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_RARP as u16).to_be() as u32));
1143 #[cfg(linux_kernel)]
1145 pub const ATALK: Protocol = Protocol(new_raw_protocol((c::ETH_P_ATALK as u16).to_be() as u32));
1146 #[cfg(linux_kernel)]
1148 pub const AARP: Protocol = Protocol(new_raw_protocol((c::ETH_P_AARP as u16).to_be() as u32));
1149 #[cfg(linux_kernel)]
1151 pub const P_8021Q: Protocol =
1152 Protocol(new_raw_protocol((c::ETH_P_8021Q as u16).to_be() as u32));
1153 #[cfg(linux_kernel)]
1155 pub const ERSPAN: Protocol =
1156 Protocol(new_raw_protocol((c::ETH_P_ERSPAN as u16).to_be() as u32));
1157 #[cfg(linux_kernel)]
1159 pub const IPX: Protocol = Protocol(new_raw_protocol((c::ETH_P_IPX as u16).to_be() as u32));
1160 #[cfg(linux_kernel)]
1162 pub const IPV6: Protocol = Protocol(new_raw_protocol((c::ETH_P_IPV6 as u16).to_be() as u32));
1163 #[cfg(linux_kernel)]
1165 pub const PAUSE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAUSE as u16).to_be() as u32));
1166 #[cfg(linux_kernel)]
1168 pub const SLOW: Protocol = Protocol(new_raw_protocol((c::ETH_P_SLOW as u16).to_be() as u32));
1169 #[cfg(linux_kernel)]
1171 pub const WCCP: Protocol = Protocol(new_raw_protocol((c::ETH_P_WCCP as u16).to_be() as u32));
1172 #[cfg(linux_kernel)]
1174 pub const MPLS_UC: Protocol =
1175 Protocol(new_raw_protocol((c::ETH_P_MPLS_UC as u16).to_be() as u32));
1176 #[cfg(linux_kernel)]
1178 pub const MPLS_MC: Protocol =
1179 Protocol(new_raw_protocol((c::ETH_P_MPLS_MC as u16).to_be() as u32));
1180 #[cfg(linux_kernel)]
1182 pub const ATMMPOA: Protocol =
1183 Protocol(new_raw_protocol((c::ETH_P_ATMMPOA as u16).to_be() as u32));
1184 #[cfg(linux_kernel)]
1186 pub const PPP_DISC: Protocol =
1187 Protocol(new_raw_protocol((c::ETH_P_PPP_DISC as u16).to_be() as u32));
1188 #[cfg(linux_kernel)]
1190 pub const PPP_SES: Protocol =
1191 Protocol(new_raw_protocol((c::ETH_P_PPP_SES as u16).to_be() as u32));
1192 #[cfg(linux_kernel)]
1194 pub const LINK_CTL: Protocol =
1195 Protocol(new_raw_protocol((c::ETH_P_LINK_CTL as u16).to_be() as u32));
1196 #[cfg(linux_kernel)]
1198 pub const ATMFATE: Protocol =
1199 Protocol(new_raw_protocol((c::ETH_P_ATMFATE as u16).to_be() as u32));
1200 #[cfg(linux_kernel)]
1202 pub const PAE: Protocol = Protocol(new_raw_protocol((c::ETH_P_PAE as u16).to_be() as u32));
1203 #[cfg(linux_kernel)]
1205 pub const PROFINET: Protocol =
1206 Protocol(new_raw_protocol((c::ETH_P_PROFINET as u16).to_be() as u32));
1207 #[cfg(linux_kernel)]
1209 pub const REALTEK: Protocol =
1210 Protocol(new_raw_protocol((c::ETH_P_REALTEK as u16).to_be() as u32));
1211 #[cfg(linux_kernel)]
1213 pub const AOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_AOE as u16).to_be() as u32));
1214 #[cfg(linux_kernel)]
1216 pub const ETHERCAT: Protocol =
1217 Protocol(new_raw_protocol((c::ETH_P_ETHERCAT as u16).to_be() as u32));
1218 #[cfg(linux_kernel)]
1220 pub const P_8021AD: Protocol =
1221 Protocol(new_raw_protocol((c::ETH_P_8021AD as u16).to_be() as u32));
1222 #[cfg(linux_kernel)]
1224 pub const P_802_EX1: Protocol =
1225 Protocol(new_raw_protocol((c::ETH_P_802_EX1 as u16).to_be() as u32));
1226 #[cfg(linux_kernel)]
1228 pub const PREAUTH: Protocol =
1229 Protocol(new_raw_protocol((c::ETH_P_PREAUTH as u16).to_be() as u32));
1230 #[cfg(linux_kernel)]
1232 pub const TIPC: Protocol = Protocol(new_raw_protocol((c::ETH_P_TIPC as u16).to_be() as u32));
1233 #[cfg(linux_kernel)]
1235 pub const LLDP: Protocol = Protocol(new_raw_protocol((c::ETH_P_LLDP as u16).to_be() as u32));
1236 #[cfg(linux_kernel)]
1238 pub const MRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MRP as u16).to_be() as u32));
1239 #[cfg(linux_kernel)]
1241 pub const MACSEC: Protocol =
1242 Protocol(new_raw_protocol((c::ETH_P_MACSEC as u16).to_be() as u32));
1243 #[cfg(linux_kernel)]
1245 pub const P_8021AH: Protocol =
1246 Protocol(new_raw_protocol((c::ETH_P_8021AH as u16).to_be() as u32));
1247 #[cfg(linux_kernel)]
1249 pub const MVRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MVRP as u16).to_be() as u32));
1250 #[cfg(linux_kernel)]
1252 pub const P_1588: Protocol = Protocol(new_raw_protocol((c::ETH_P_1588 as u16).to_be() as u32));
1253 #[cfg(linux_kernel)]
1255 pub const NCSI: Protocol = Protocol(new_raw_protocol((c::ETH_P_NCSI as u16).to_be() as u32));
1256 #[cfg(linux_kernel)]
1258 pub const PRP: Protocol = Protocol(new_raw_protocol((c::ETH_P_PRP as u16).to_be() as u32));
1259 #[cfg(linux_kernel)]
1261 pub const CFM: Protocol = Protocol(new_raw_protocol((c::ETH_P_CFM as u16).to_be() as u32));
1262 #[cfg(linux_kernel)]
1264 pub const FCOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_FCOE as u16).to_be() as u32));
1265 #[cfg(linux_kernel)]
1267 pub const IBOE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IBOE as u16).to_be() as u32));
1268 #[cfg(linux_kernel)]
1270 pub const TDLS: Protocol = Protocol(new_raw_protocol((c::ETH_P_TDLS as u16).to_be() as u32));
1271 #[cfg(linux_kernel)]
1273 pub const FIP: Protocol = Protocol(new_raw_protocol((c::ETH_P_FIP as u16).to_be() as u32));
1274 #[cfg(linux_kernel)]
1276 pub const P_80221: Protocol =
1277 Protocol(new_raw_protocol((c::ETH_P_80221 as u16).to_be() as u32));
1278 #[cfg(linux_kernel)]
1280 pub const HSR: Protocol = Protocol(new_raw_protocol((c::ETH_P_HSR as u16).to_be() as u32));
1281 #[cfg(linux_kernel)]
1283 pub const NSH: Protocol = Protocol(new_raw_protocol((c::ETH_P_NSH as u16).to_be() as u32));
1284 #[cfg(linux_kernel)]
1286 pub const LOOPBACK: Protocol =
1287 Protocol(new_raw_protocol((c::ETH_P_LOOPBACK as u16).to_be() as u32));
1288 #[cfg(linux_kernel)]
1290 pub const QINQ1: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ1 as u16).to_be() as u32));
1291 #[cfg(linux_kernel)]
1293 pub const QINQ2: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ2 as u16).to_be() as u32));
1294 #[cfg(linux_kernel)]
1296 pub const QINQ3: Protocol = Protocol(new_raw_protocol((c::ETH_P_QINQ3 as u16).to_be() as u32));
1297 #[cfg(linux_kernel)]
1299 pub const EDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_EDSA as u16).to_be() as u32));
1300 #[cfg(linux_kernel)]
1302 pub const DSA_8021Q: Protocol =
1303 Protocol(new_raw_protocol((c::ETH_P_DSA_8021Q as u16).to_be() as u32));
1304 #[cfg(linux_kernel)]
1306 pub const DSA_A5PSW: Protocol =
1307 Protocol(new_raw_protocol((c::ETH_P_DSA_A5PSW as u16).to_be() as u32));
1308 #[cfg(linux_kernel)]
1310 pub const IFE: Protocol = Protocol(new_raw_protocol((c::ETH_P_IFE as u16).to_be() as u32));
1311 #[cfg(linux_kernel)]
1313 pub const AF_IUCV: Protocol =
1314 Protocol(new_raw_protocol((c::ETH_P_AF_IUCV as u16).to_be() as u32));
1315 #[cfg(linux_kernel)]
1317 pub const P_802_3_MIN: Protocol =
1318 Protocol(new_raw_protocol((c::ETH_P_802_3_MIN as u16).to_be() as u32));
1319 #[cfg(linux_kernel)]
1321 pub const P_802_3: Protocol =
1322 Protocol(new_raw_protocol((c::ETH_P_802_3 as u16).to_be() as u32));
1323 #[cfg(linux_kernel)]
1325 pub const AX25: Protocol = Protocol(new_raw_protocol((c::ETH_P_AX25 as u16).to_be() as u32));
1326 #[cfg(linux_kernel)]
1328 pub const ALL: Protocol = Protocol(new_raw_protocol((c::ETH_P_ALL as u16).to_be() as u32));
1329 #[cfg(linux_kernel)]
1331 pub const P_802_2: Protocol =
1332 Protocol(new_raw_protocol((c::ETH_P_802_2 as u16).to_be() as u32));
1333 #[cfg(linux_kernel)]
1335 pub const SNAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_SNAP as u16).to_be() as u32));
1336 #[cfg(linux_kernel)]
1338 pub const DDCMP: Protocol = Protocol(new_raw_protocol((c::ETH_P_DDCMP as u16).to_be() as u32));
1339 #[cfg(linux_kernel)]
1341 pub const WAN_PPP: Protocol =
1342 Protocol(new_raw_protocol((c::ETH_P_WAN_PPP as u16).to_be() as u32));
1343 #[cfg(linux_kernel)]
1345 pub const PPP_MP: Protocol =
1346 Protocol(new_raw_protocol((c::ETH_P_PPP_MP as u16).to_be() as u32));
1347 #[cfg(linux_kernel)]
1349 pub const LOCALTALK: Protocol =
1350 Protocol(new_raw_protocol((c::ETH_P_LOCALTALK as u16).to_be() as u32));
1351 #[cfg(linux_kernel)]
1353 pub const CAN: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAN as u16).to_be() as u32));
1354 #[cfg(linux_kernel)]
1356 pub const CANFD: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANFD as u16).to_be() as u32));
1357 #[cfg(linux_kernel)]
1359 pub const CANXL: Protocol = Protocol(new_raw_protocol((c::ETH_P_CANXL as u16).to_be() as u32));
1360 #[cfg(linux_kernel)]
1362 pub const PPPTALK: Protocol =
1363 Protocol(new_raw_protocol((c::ETH_P_PPPTALK as u16).to_be() as u32));
1364 #[cfg(linux_kernel)]
1366 pub const TR_802_2: Protocol =
1367 Protocol(new_raw_protocol((c::ETH_P_TR_802_2 as u16).to_be() as u32));
1368 #[cfg(linux_kernel)]
1370 pub const MOBITEX: Protocol =
1371 Protocol(new_raw_protocol((c::ETH_P_MOBITEX as u16).to_be() as u32));
1372 #[cfg(linux_kernel)]
1374 pub const CONTROL: Protocol =
1375 Protocol(new_raw_protocol((c::ETH_P_CONTROL as u16).to_be() as u32));
1376 #[cfg(linux_kernel)]
1378 pub const IRDA: Protocol = Protocol(new_raw_protocol((c::ETH_P_IRDA as u16).to_be() as u32));
1379 #[cfg(linux_kernel)]
1381 pub const ECONET: Protocol =
1382 Protocol(new_raw_protocol((c::ETH_P_ECONET as u16).to_be() as u32));
1383 #[cfg(linux_kernel)]
1385 pub const HDLC: Protocol = Protocol(new_raw_protocol((c::ETH_P_HDLC as u16).to_be() as u32));
1386 #[cfg(linux_kernel)]
1388 pub const ARCNET: Protocol =
1389 Protocol(new_raw_protocol((c::ETH_P_ARCNET as u16).to_be() as u32));
1390 #[cfg(linux_kernel)]
1392 pub const DSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_DSA as u16).to_be() as u32));
1393 #[cfg(linux_kernel)]
1395 pub const TRAILER: Protocol =
1396 Protocol(new_raw_protocol((c::ETH_P_TRAILER as u16).to_be() as u32));
1397 #[cfg(linux_kernel)]
1399 pub const PHONET: Protocol =
1400 Protocol(new_raw_protocol((c::ETH_P_PHONET as u16).to_be() as u32));
1401 #[cfg(linux_kernel)]
1403 pub const IEEE802154: Protocol =
1404 Protocol(new_raw_protocol((c::ETH_P_IEEE802154 as u16).to_be() as u32));
1405 #[cfg(linux_kernel)]
1407 pub const CAIF: Protocol = Protocol(new_raw_protocol((c::ETH_P_CAIF as u16).to_be() as u32));
1408 #[cfg(linux_kernel)]
1410 pub const XDSA: Protocol = Protocol(new_raw_protocol((c::ETH_P_XDSA as u16).to_be() as u32));
1411 #[cfg(linux_kernel)]
1413 pub const MAP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MAP as u16).to_be() as u32));
1414 #[cfg(linux_kernel)]
1416 pub const MCTP: Protocol = Protocol(new_raw_protocol((c::ETH_P_MCTP as u16).to_be() as u32));
1417}
1418
1419#[rustfmt::skip]
1420impl Protocol {
1421 #[inline]
1423 pub const fn from_raw(raw: RawProtocol) -> Self {
1424 Self(raw)
1425 }
1426
1427 #[inline]
1429 pub const fn as_raw(self) -> RawProtocol {
1430 self.0
1431 }
1432}
1433
1434#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
1438#[repr(u32)]
1439pub enum Shutdown {
1440 Read = c::SHUT_RD as _,
1442 Write = c::SHUT_WR as _,
1444 ReadWrite = c::SHUT_RDWR as _,
1446}
1447
1448bitflags! {
1449 #[repr(transparent)]
1456 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1457 pub struct SocketFlags: c::c_uint {
1458 #[cfg(not(any(
1460 apple,
1461 windows,
1462 target_os = "aix",
1463 target_os = "espidf",
1464 target_os = "haiku",
1465 target_os = "nto",
1466 target_os = "vita",
1467 )))]
1468 const NONBLOCK = bitcast!(c::SOCK_NONBLOCK);
1469
1470 #[cfg(not(any(apple, windows, target_os = "aix", target_os = "haiku")))]
1472 const CLOEXEC = bitcast!(c::SOCK_CLOEXEC);
1473
1474 }
1478}
1479
1480#[cfg(target_os = "linux")]
1482pub mod xdp {
1483 use super::{bitflags, c};
1484
1485 bitflags! {
1486 #[repr(transparent)]
1490 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1491 pub struct XdpOptionsFlags: u32 {
1492 const XDP_OPTIONS_ZEROCOPY = bitcast!(c::XDP_OPTIONS_ZEROCOPY);
1494 }
1495 }
1496
1497 bitflags! {
1500 #[repr(transparent)]
1502 #[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
1503 pub struct SockaddrXdpFlags: u16 {
1504 const XDP_SHARED_UMEM = bitcast!(c::XDP_SHARED_UMEM as u16);
1506 const XDP_COPY = bitcast!(c::XDP_COPY as u16);
1508 const XDP_ZEROCOPY = bitcast!(c::XDP_ZEROCOPY as u16);
1510 const XDP_USE_NEED_WAKEUP = bitcast!(c::XDP_USE_NEED_WAKEUP as u16);
1512 const XDP_USE_SG = bitcast!(c::XDP_USE_SG as u16);
1515 }
1516 }
1517
1518 bitflags! {
1519 #[repr(transparent)]
1521 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1522 pub struct XdpRingFlags: u32 {
1523 const XDP_RING_NEED_WAKEUP = bitcast!(c::XDP_RING_NEED_WAKEUP);
1525 }
1526 }
1527
1528 bitflags! {
1529 #[repr(transparent)]
1531 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1532 pub struct XdpUmemRegFlags: u32 {
1533 const XDP_UMEM_UNALIGNED_CHUNK_FLAG = bitcast!(c::XDP_UMEM_UNALIGNED_CHUNK_FLAG);
1535 }
1536 }
1537
1538 #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
1545 pub struct SocketAddrXdp {
1546 sxdp_flags: SockaddrXdpFlags,
1548 sxdp_ifindex: u32,
1550 sxdp_queue_id: u32,
1552 sxdp_shared_umem_fd: u32,
1554 }
1555
1556 impl SocketAddrXdp {
1557 #[inline]
1559 pub fn new(
1560 flags: SockaddrXdpFlags,
1561 interface_index: u32,
1562 queue_id: u32,
1563 share_umem_fd: u32,
1564 ) -> Self {
1565 Self {
1566 sxdp_flags: flags,
1567 sxdp_ifindex: interface_index,
1568 sxdp_queue_id: queue_id,
1569 sxdp_shared_umem_fd: share_umem_fd,
1570 }
1571 }
1572
1573 #[inline]
1575 pub fn flags(&self) -> SockaddrXdpFlags {
1576 self.sxdp_flags
1577 }
1578
1579 #[inline]
1581 pub fn set_flags(&mut self, flags: SockaddrXdpFlags) {
1582 self.sxdp_flags = flags;
1583 }
1584
1585 #[inline]
1587 pub fn interface_index(&self) -> u32 {
1588 self.sxdp_ifindex
1589 }
1590
1591 #[inline]
1593 pub fn set_interface_index(&mut self, interface_index: u32) {
1594 self.sxdp_ifindex = interface_index;
1595 }
1596
1597 #[inline]
1599 pub fn queue_id(&self) -> u32 {
1600 self.sxdp_queue_id
1601 }
1602
1603 #[inline]
1605 pub fn set_queue_id(&mut self, queue_id: u32) {
1606 self.sxdp_queue_id = queue_id;
1607 }
1608
1609 #[inline]
1611 pub fn shared_umem_fd(&self) -> u32 {
1612 self.sxdp_shared_umem_fd
1613 }
1614
1615 #[inline]
1617 pub fn set_shared_umem_fd(&mut self, shared_umem_fd: u32) {
1618 self.sxdp_shared_umem_fd = shared_umem_fd;
1619 }
1620 }
1621
1622 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1629 pub struct XdpRingOffset {
1630 pub producer: u64,
1632 pub consumer: u64,
1634 pub desc: u64,
1636 pub flags: Option<u64>,
1640 }
1641
1642 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1647 pub struct XdpMmapOffsets {
1648 pub rx: XdpRingOffset,
1650 pub tx: XdpRingOffset,
1652 pub fr: XdpRingOffset,
1654 pub cr: XdpRingOffset,
1656 }
1657
1658 #[repr(C)]
1663 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1664 pub struct XdpUmemReg {
1665 pub addr: u64,
1667 pub len: u64,
1669 pub chunk_size: u32,
1671 pub headroom: u32,
1673 pub flags: XdpUmemRegFlags,
1677 }
1678
1679 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1684 pub struct XdpStatistics {
1685 pub rx_dropped: u64,
1687 pub rx_invalid_descs: u64,
1689 pub tx_invalid_descs: u64,
1691 pub rx_ring_full: Option<u64>,
1695 pub rx_fill_ring_empty_descs: Option<u64>,
1699 pub tx_ring_empty_descs: Option<u64>,
1703 }
1704
1705 #[repr(C)]
1711 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1712 pub struct XdpOptions {
1713 pub flags: XdpOptionsFlags,
1715 }
1716
1717 #[repr(C)]
1722 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1723 pub struct XdpDesc {
1724 pub addr: u64,
1726 pub len: u32,
1728 pub options: XdpDescOptions,
1730 }
1731
1732 #[cfg(target_os = "linux")]
1733 bitflags! {
1734 #[repr(transparent)]
1735 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
1736 pub struct XdpDescOptions: u32 {
1740 const XDP_PKT_CONTD = bitcast!(c::XDP_PKT_CONTD);
1742 }
1743 }
1744
1745 pub const XDP_PGOFF_RX_RING: u64 = c::XDP_PGOFF_RX_RING as u64;
1747 pub const XDP_PGOFF_TX_RING: u64 = c::XDP_PGOFF_TX_RING as u64;
1749 pub const XDP_UMEM_PGOFF_FILL_RING: u64 = c::XDP_UMEM_PGOFF_FILL_RING;
1751 pub const XDP_UMEM_PGOFF_COMPLETION_RING: u64 = c::XDP_UMEM_PGOFF_COMPLETION_RING;
1753
1754 pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: u64 = c::XSK_UNALIGNED_BUF_OFFSET_SHIFT as u64;
1757 pub const XSK_UNALIGNED_BUF_ADDR_MASK: u64 = c::XSK_UNALIGNED_BUF_ADDR_MASK;
1761}
1762
1763#[cfg(linux_kernel)]
1771#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
1772#[repr(C)]
1773pub struct UCred {
1774 pub pid: crate::pid::Pid,
1776 pub uid: crate::ugid::Uid,
1778 pub gid: crate::ugid::Gid,
1780}
1781
1782#[test]
1783fn test_sizes() {
1784 use crate::backend::c;
1785 use c::c_int;
1786 use core::mem::transmute;
1787
1788 assert_eq_size!(RawProtocol, c_int);
1791 assert_eq_size!(Protocol, c_int);
1792 assert_eq_size!(Option<RawProtocol>, c_int);
1793 assert_eq_size!(Option<Protocol>, c_int);
1794 assert_eq_size!(RawSocketType, c_int);
1795 assert_eq_size!(SocketType, c_int);
1796 assert_eq_size!(SocketFlags, c_int);
1797
1798 #[allow(unsafe_code)]
1801 unsafe {
1802 let t: Option<Protocol> = None;
1803 assert_eq!(0_u32, transmute::<Option<Protocol>, u32>(t));
1804
1805 let t: Option<Protocol> = Some(Protocol::from_raw(RawProtocol::new(4567).unwrap()));
1806 assert_eq!(4567_u32, transmute::<Option<Protocol>, u32>(t));
1807 }
1808
1809 #[cfg(linux_kernel)]
1810 assert_eq_size!(UCred, libc::ucred);
1811
1812 #[cfg(target_os = "linux")]
1818 assert_eq_size!(super::xdp::XdpOptions, c::xdp_options);
1819 #[cfg(target_os = "linux")]
1820 assert_eq_size!(super::xdp::XdpDesc, c::xdp_desc);
1821}