@@ -6,94 +6,96 @@ extern crate libc;
6
6
#[cfg(unix)]
7
7
mod t {
8
8
9
- use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr};
10
- use std::mem;
9
+ use libc::{self, c_uchar, c_uint, c_void, cmsghdr, msghdr};
10
+ use std::mem;
11
11
12
- extern {
13
- pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr;
14
- pub fn cmsg_nxthdr(mhdr: *const msghdr,
15
- cmsg: *const cmsghdr) -> *mut cmsghdr;
16
- pub fn cmsg_space(length: c_uint) -> usize;
17
- pub fn cmsg_len(length: c_uint) -> usize;
18
- pub fn cmsg_data(cmsg: *const cmsghdr) -> *mut c_uchar;
19
- }
12
+ extern "C" {
13
+ pub fn cmsg_firsthdr(msgh: *const msghdr) -> *mut cmsghdr;
14
+ pub fn cmsg_nxthdr(
15
+ mhdr: *const msghdr,
16
+ cmsg: *const cmsghdr,
17
+ ) -> *mut cmsghdr;
18
+ pub fn cmsg_space(length: c_uint) -> usize;
19
+ pub fn cmsg_len(length: c_uint) -> usize;
20
+ pub fn cmsg_data(cmsg: *const cmsghdr) -> *mut c_uchar;
21
+ }
20
22
21
- #[test]
22
- fn test_cmsg_data() {
23
- for l in 0..128 {
24
- let pcmsghdr = l as *const cmsghdr;
25
- unsafe {
26
- assert_eq!(libc::CMSG_DATA(pcmsghdr), cmsg_data(pcmsghdr));
23
+ #[test]
24
+ fn test_cmsg_data() {
25
+ for l in 0..128 {
26
+ let pcmsghdr = l as *const cmsghdr;
27
+ unsafe {
28
+ assert_eq!(libc::CMSG_DATA(pcmsghdr), cmsg_data(pcmsghdr));
29
+ }
27
30
}
28
31
}
29
- }
30
32
31
- #[test]
32
- fn test_cmsg_firsthdr() {
33
- let mut mhdr: msghdr = unsafe{mem::zeroed()};
34
- mhdr.msg_control = 0xdeadbeef as *mut c_void;
35
- let pmhdr = &mhdr as *const msghdr;
36
- for l in 0..128 {
37
- mhdr.msg_controllen = l;
38
- unsafe {
39
- assert_eq!(libc::CMSG_FIRSTHDR(pmhdr), cmsg_firsthdr(pmhdr));
33
+ #[test]
34
+ fn test_cmsg_firsthdr() {
35
+ let mut mhdr: msghdr = unsafe { mem::zeroed() };
36
+ mhdr.msg_control = 0xdeadbeef as *mut c_void;
37
+ let pmhdr = &mhdr as *const msghdr;
38
+ for l in 0..128 {
39
+ mhdr.msg_controllen = l;
40
+ unsafe {
41
+ assert_eq!(libc::CMSG_FIRSTHDR(pmhdr), cmsg_firsthdr(pmhdr));
42
+ }
40
43
}
41
44
}
42
- }
43
45
44
- #[test]
45
- fn test_cmsg_len() {
46
- for l in 0..128 {
47
- unsafe {
48
- assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l));
46
+ #[test]
47
+ fn test_cmsg_len() {
48
+ for l in 0..128 {
49
+ unsafe {
50
+ assert_eq!(libc::CMSG_LEN(l) as usize, cmsg_len(l));
51
+ }
49
52
}
50
53
}
51
- }
52
-
53
- // Skip on sparc64
54
- // https://github.com/rust-lang/libc/issues/1239
55
- #[cfg(not(target_arch = "sparc64"))]
56
- #[test]
57
- fn test_cmsg_nxthdr() {
58
- use std::ptr;
59
54
60
- let mut buffer = [0u8; 256];
61
- let mut mhdr: msghdr = unsafe{mem::zeroed()};
62
- let pmhdr = &mhdr as *const msghdr;
63
- for start_ofs in 0..64 {
64
- let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr;
65
- mhdr.msg_control = pcmsghdr as *mut c_void;
66
- mhdr.msg_controllen = (160 - start_ofs) as _;
67
- for cmsg_len in 0..64 {
68
- for next_cmsg_len in 0..32 {
69
- for i in buffer[start_ofs..].iter_mut() {
70
- *i = 0;
71
- }
72
- unsafe {
73
- (*pcmsghdr).cmsg_len = cmsg_len;
74
- let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr);
75
- let next = cmsg_nxthdr(pmhdr, pcmsghdr);
76
- assert_eq!(libc_next, next);
55
+ // Skip on sparc64
56
+ // https://github.com/rust-lang/libc/issues/1239
57
+ #[cfg(not(target_arch = "sparc64"))]
58
+ #[test]
59
+ fn test_cmsg_nxthdr() {
60
+ use std::ptr;
77
61
78
- if libc_next != ptr::null_mut() {
79
- (*libc_next).cmsg_len = next_cmsg_len;
62
+ let mut buffer = [0u8; 256];
63
+ let mut mhdr: msghdr = unsafe { mem::zeroed() };
64
+ let pmhdr = &mhdr as *const msghdr;
65
+ for start_ofs in 0..64 {
66
+ let pcmsghdr = &mut buffer[start_ofs] as *mut u8 as *mut cmsghdr;
67
+ mhdr.msg_control = pcmsghdr as *mut c_void;
68
+ mhdr.msg_controllen = (160 - start_ofs) as _;
69
+ for cmsg_len in 0..64 {
70
+ for next_cmsg_len in 0..32 {
71
+ for i in buffer[start_ofs..].iter_mut() {
72
+ *i = 0;
73
+ }
74
+ unsafe {
75
+ (*pcmsghdr).cmsg_len = cmsg_len;
80
76
let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr);
81
77
let next = cmsg_nxthdr(pmhdr, pcmsghdr);
82
78
assert_eq!(libc_next, next);
79
+
80
+ if libc_next != ptr::null_mut() {
81
+ (*libc_next).cmsg_len = next_cmsg_len;
82
+ let libc_next = libc::CMSG_NXTHDR(pmhdr, pcmsghdr);
83
+ let next = cmsg_nxthdr(pmhdr, pcmsghdr);
84
+ assert_eq!(libc_next, next);
85
+ }
83
86
}
84
87
}
85
88
}
86
89
}
87
90
}
88
- }
89
91
90
- #[test]
91
- fn test_cmsg_space() {
92
- unsafe {
93
- for l in 0..128 {
94
- assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l));
92
+ #[test]
93
+ fn test_cmsg_space() {
94
+ unsafe {
95
+ for l in 0..128 {
96
+ assert_eq!(libc::CMSG_SPACE(l) as usize, cmsg_space(l));
97
+ }
95
98
}
96
99
}
97
- }
98
100
99
101
}
0 commit comments