Skip to content

Commit 9aec841

Browse files
committed
qnx: add missing BPF and ifreq structures
1 parent 7b336ae commit 9aec841

File tree

1 file changed

+320
-1
lines changed

1 file changed

+320
-1
lines changed

src/unix/nto/mod.rs

Lines changed: 320 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,13 @@ s! {
670670
pub uc_stack: stack_t,
671671
pub uc_mcontext: mcontext_t,
672672
}
673+
pub struct ifreq_buffer {
674+
pub length: size_t,
675+
pub buffer: *mut c_void,
676+
}
677+
}
678+
679+
s_no_extra_traits! {
673680
pub struct sockaddr_un {
674681
pub sun_len: u8,
675682
pub sun_family: sa_family_t,
@@ -795,6 +802,239 @@ s_no_extra_traits! {
795802
pub __owner: c_uint,
796803
pub __spare: c_uint,
797804
}
805+
806+
pub union __c_anonymous_ifr_ifru {
807+
pub ifru_addr: crate::sockaddr,
808+
pub ifru_dstaddr: crate::sockaddr,
809+
pub ifru_broadaddr: crate::sockaddr,
810+
pub ifru_buffer: ifreq_buffer,
811+
pub ifru_flags: [c_short; 2],
812+
pub ifru_index: c_short,
813+
pub ifru_jid: c_int,
814+
pub ifru_metric: c_int,
815+
pub ifru_mtu: c_int,
816+
pub ifru_phys: c_int,
817+
pub ifru_media: c_int,
818+
pub ifru_data: *mut c_char,
819+
pub ifru_cap: [c_int; 2],
820+
pub ifru_fib: c_uint,
821+
pub ifru_vlan_pcp: c_uchar,
822+
}
823+
824+
pub struct ifreq {
825+
/// if name, e.g. "en0"
826+
pub ifr_name: [c_char; crate::IFNAMSIZ],
827+
pub ifr_ifru: __c_anonymous_ifr_ifru,
828+
}
829+
}
830+
831+
cfg_if! {
832+
if #[cfg(feature = "extra_traits")] {
833+
// sigevent
834+
impl PartialEq for sigevent {
835+
fn eq(&self, other: &sigevent) -> bool {
836+
self.sigev_notify == other.sigev_notify
837+
&& self.sigev_signo == other.sigev_signo
838+
&& self.sigev_value == other.sigev_value
839+
&& self.__sigev_un2 == other.__sigev_un2
840+
}
841+
}
842+
impl Eq for sigevent {}
843+
impl hash::Hash for sigevent {
844+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
845+
self.sigev_notify.hash(state);
846+
self.sigev_signo.hash(state);
847+
self.sigev_value.hash(state);
848+
self.__sigev_un2.hash(state);
849+
}
850+
}
851+
852+
impl PartialEq for sockaddr_un {
853+
fn eq(&self, other: &sockaddr_un) -> bool {
854+
self.sun_len == other.sun_len
855+
&& self.sun_family == other.sun_family
856+
&& self
857+
.sun_path
858+
.iter()
859+
.zip(other.sun_path.iter())
860+
.all(|(a, b)| a == b)
861+
}
862+
}
863+
impl Eq for sockaddr_un {}
864+
865+
impl hash::Hash for sockaddr_un {
866+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
867+
self.sun_len.hash(state);
868+
self.sun_family.hash(state);
869+
self.sun_path.hash(state);
870+
}
871+
}
872+
873+
// sigset_t
874+
impl PartialEq for sigset_t {
875+
fn eq(&self, other: &sigset_t) -> bool {
876+
self.__val == other.__val
877+
}
878+
}
879+
impl Eq for sigset_t {}
880+
impl hash::Hash for sigset_t {
881+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
882+
self.__val.hash(state);
883+
}
884+
}
885+
886+
// msg
887+
888+
// msqid_ds
889+
890+
// sockaddr_dl
891+
impl PartialEq for sockaddr_dl {
892+
fn eq(&self, other: &sockaddr_dl) -> bool {
893+
self.sdl_len == other.sdl_len
894+
&& self.sdl_family == other.sdl_family
895+
&& self.sdl_index == other.sdl_index
896+
&& self.sdl_type == other.sdl_type
897+
&& self.sdl_nlen == other.sdl_nlen
898+
&& self.sdl_alen == other.sdl_alen
899+
&& self.sdl_slen == other.sdl_slen
900+
&& self
901+
.sdl_data
902+
.iter()
903+
.zip(other.sdl_data.iter())
904+
.all(|(a, b)| a == b)
905+
}
906+
}
907+
impl Eq for sockaddr_dl {}
908+
impl hash::Hash for sockaddr_dl {
909+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
910+
self.sdl_len.hash(state);
911+
self.sdl_family.hash(state);
912+
self.sdl_index.hash(state);
913+
self.sdl_type.hash(state);
914+
self.sdl_nlen.hash(state);
915+
self.sdl_alen.hash(state);
916+
self.sdl_slen.hash(state);
917+
self.sdl_data.hash(state);
918+
}
919+
}
920+
921+
impl PartialEq for utsname {
922+
fn eq(&self, other: &utsname) -> bool {
923+
self.sysname
924+
.iter()
925+
.zip(other.sysname.iter())
926+
.all(|(a, b)| a == b)
927+
&& self
928+
.nodename
929+
.iter()
930+
.zip(other.nodename.iter())
931+
.all(|(a, b)| a == b)
932+
&& self
933+
.release
934+
.iter()
935+
.zip(other.release.iter())
936+
.all(|(a, b)| a == b)
937+
&& self
938+
.version
939+
.iter()
940+
.zip(other.version.iter())
941+
.all(|(a, b)| a == b)
942+
&& self
943+
.machine
944+
.iter()
945+
.zip(other.machine.iter())
946+
.all(|(a, b)| a == b)
947+
}
948+
}
949+
950+
impl Eq for utsname {}
951+
952+
impl hash::Hash for utsname {
953+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
954+
self.sysname.hash(state);
955+
self.nodename.hash(state);
956+
self.release.hash(state);
957+
self.version.hash(state);
958+
self.machine.hash(state);
959+
}
960+
}
961+
962+
impl PartialEq for mq_attr {
963+
fn eq(&self, other: &mq_attr) -> bool {
964+
self.mq_maxmsg == other.mq_maxmsg
965+
&& self.mq_msgsize == other.mq_msgsize
966+
&& self.mq_flags == other.mq_flags
967+
&& self.mq_curmsgs == other.mq_curmsgs
968+
&& self.mq_msgsize == other.mq_msgsize
969+
&& self.mq_sendwait == other.mq_sendwait
970+
&& self.mq_recvwait == other.mq_recvwait
971+
}
972+
}
973+
974+
impl Eq for mq_attr {}
975+
976+
impl hash::Hash for mq_attr {
977+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
978+
self.mq_maxmsg.hash(state);
979+
self.mq_msgsize.hash(state);
980+
self.mq_flags.hash(state);
981+
self.mq_curmsgs.hash(state);
982+
self.mq_sendwait.hash(state);
983+
self.mq_recvwait.hash(state);
984+
}
985+
}
986+
987+
impl PartialEq for sockaddr_storage {
988+
fn eq(&self, other: &sockaddr_storage) -> bool {
989+
self.ss_len == other.ss_len
990+
&& self.ss_family == other.ss_family
991+
&& self.__ss_pad1 == other.__ss_pad1
992+
&& self.__ss_align == other.__ss_align
993+
&& self
994+
.__ss_pad2
995+
.iter()
996+
.zip(other.__ss_pad2.iter())
997+
.all(|(a, b)| a == b)
998+
}
999+
}
1000+
1001+
impl Eq for sockaddr_storage {}
1002+
1003+
impl hash::Hash for sockaddr_storage {
1004+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
1005+
self.ss_len.hash(state);
1006+
self.ss_family.hash(state);
1007+
self.__ss_pad1.hash(state);
1008+
self.__ss_align.hash(state);
1009+
self.__ss_pad2.hash(state);
1010+
}
1011+
}
1012+
1013+
impl PartialEq for dirent {
1014+
fn eq(&self, other: &dirent) -> bool {
1015+
self.d_ino == other.d_ino
1016+
&& self.d_offset == other.d_offset
1017+
&& self.d_reclen == other.d_reclen
1018+
&& self.d_namelen == other.d_namelen
1019+
&& self.d_name[..self.d_namelen as _]
1020+
.iter()
1021+
.zip(other.d_name.iter())
1022+
.all(|(a, b)| a == b)
1023+
}
1024+
}
1025+
1026+
impl Eq for dirent {}
1027+
1028+
impl hash::Hash for dirent {
1029+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
1030+
self.d_ino.hash(state);
1031+
self.d_offset.hash(state);
1032+
self.d_reclen.hash(state);
1033+
self.d_namelen.hash(state);
1034+
self.d_name[..self.d_namelen as _].hash(state);
1035+
}
1036+
}
1037+
}
7981038
}
7991039

8001040
pub const _SYSNAME_SIZE: usize = 256 + 1;
@@ -877,7 +1117,7 @@ pub const MS_SYNC: c_int = 2;
8771117
pub const SCM_RIGHTS: c_int = 0x01;
8781118
pub const SCM_TIMESTAMP: c_int = 0x02;
8791119
cfg_if! {
880-
if #[cfg(not(target_env = "nto71_iosock"))] {
1120+
if #[cfg(not(any(target_env = "nto71_iosock", target_env = "nto80")))] {
8811121
pub const SCM_CREDS: c_int = 0x04;
8821122
pub const IFF_NOTRAILERS: c_int = 0x00000020;
8831123
pub const AF_INET6: c_int = 24;
@@ -2093,6 +2333,44 @@ pub const BIOCSRTIMEOUT: c_int = -2146418067;
20932333
pub const BIOCVERSION: c_int = 1074020977;
20942334

20952335
pub const BPF_ALIGNMENT: usize = size_of::<c_long>();
2336+
pub const BPF_LD: u16 = 0x00;
2337+
pub const BPF_LDX: u16 = 0x01;
2338+
pub const BPF_ST: u16 = 0x02;
2339+
pub const BPF_STX: u16 = 0x03;
2340+
pub const BPF_ALU: u16 = 0x04;
2341+
pub const BPF_JMP: u16 = 0x05;
2342+
pub const BPF_RET: u16 = 0x06;
2343+
pub const BPF_MISC: u16 = 0x07;
2344+
pub const BPF_W: u16 = 0x00;
2345+
pub const BPF_H: u16 = 0x08;
2346+
pub const BPF_B: u16 = 0x10;
2347+
pub const BPF_IMM: u16 = 0x00;
2348+
pub const BPF_ABS: u16 = 0x20;
2349+
pub const BPF_IND: u16 = 0x40;
2350+
pub const BPF_MEM: u16 = 0x60;
2351+
pub const BPF_LEN: u16 = 0x80;
2352+
pub const BPF_MSH: u16 = 0xa0;
2353+
pub const BPF_ADD: u16 = 0x00;
2354+
pub const BPF_SUB: u16 = 0x10;
2355+
pub const BPF_MUL: u16 = 0x20;
2356+
pub const BPF_DIV: u16 = 0x30;
2357+
pub const BPF_OR: u16 = 0x40;
2358+
pub const BPF_AND: u16 = 0x50;
2359+
pub const BPF_LSH: u16 = 0x60;
2360+
pub const BPF_RSH: u16 = 0x70;
2361+
pub const BPF_NEG: u16 = 0x80;
2362+
pub const BPF_MOD: u16 = 0x90;
2363+
pub const BPF_XOR: u16 = 0xa0;
2364+
pub const BPF_JA: u16 = 0x00;
2365+
pub const BPF_JEQ: u16 = 0x10;
2366+
pub const BPF_JGT: u16 = 0x20;
2367+
pub const BPF_JGE: u16 = 0x30;
2368+
pub const BPF_JSET: u16 = 0x40;
2369+
pub const BPF_K: u16 = 0x00;
2370+
pub const BPF_X: u16 = 0x08;
2371+
pub const BPF_A: u16 = 0x10;
2372+
pub const BPF_TAX: u16 = 0x00;
2373+
pub const BPF_TXA: u16 = 0x80;
20962374
pub const CHAR_BIT: usize = 8;
20972375
pub const CODESET: crate::nl_item = 1;
20982376
pub const CRNCYSTR: crate::nl_item = 55;
@@ -2483,6 +2761,47 @@ f! {
24832761
let ngrps = if ngrps > 0 { ngrps - 1 } else { 0 };
24842762
size_of::<sockcred>() + size_of::<crate::gid_t>() * ngrps
24852763
}
2764+
2765+
pub fn BPF_CLASS(code: u32) -> u32 {
2766+
code & 0x07
2767+
}
2768+
2769+
pub fn BPF_SIZE(code: u32) -> u32 {
2770+
code & 0x18
2771+
}
2772+
2773+
pub fn BPF_MODE(code: u32) -> u32 {
2774+
code & 0xe0
2775+
}
2776+
2777+
pub fn BPF_OP(code: u32) -> u32 {
2778+
code & 0xf0
2779+
}
2780+
2781+
pub fn BPF_SRC(code: u32) -> u32 {
2782+
code & 0x08
2783+
}
2784+
2785+
pub fn BPF_RVAL(code: u32) -> u32 {
2786+
code & 0x18
2787+
}
2788+
2789+
pub fn BPF_MISCOP(code: u32) -> u32 {
2790+
code & 0xf8
2791+
}
2792+
2793+
pub fn BPF_STMT(code: u16, k: u32) -> bpf_insn {
2794+
bpf_insn {
2795+
code,
2796+
jt: 0,
2797+
jf: 0,
2798+
k,
2799+
}
2800+
}
2801+
2802+
pub fn BPF_JUMP(code: u16, k: u32, jt: u8, jf: u8) -> bpf_insn {
2803+
bpf_insn { code, jt, jf, k }
2804+
}
24862805
}
24872806

24882807
safe_f! {

0 commit comments

Comments
 (0)