Skip to content

Commit

Permalink
Fix sendmsg on macOS when passing a zero entry cmsgs array.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinetiknz committed Jun 20, 2017
1 parent 78eca21 commit 400a77a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,18 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<'
None => (0 as *const _, 0),
};

let cmsg_ptr = if capacity > 0 {
cmsg_buffer.as_ptr() as *const c_void
} else {
ptr::null()
};

let mhdr = msghdr {
msg_name: name as *const c_void,
msg_namelen: namelen,
msg_iov: iov.as_ptr(),
msg_iovlen: iov.len() as size_t,
msg_control: cmsg_buffer.as_ptr() as *const c_void,
msg_control: cmsg_ptr,
msg_controllen: capacity as size_t,
msg_flags: 0,
};
Expand Down

0 comments on commit 400a77a

Please sign in to comment.